Abstraction Between Database Entities And Objects In C#?
Sep 17, 2011
I've just gotten started with development using Visual Studio (though this can be seen as a more language-generic question), and need done design answers regarding how to suitable relate a Database Entity/Table with an Class in-code.
Currently, I create a class who's attributes or iVars directly correspond to the fields in an Entity.
When I come to fetching all 'Customers from a Table' for example, I run a Select all statement against the database and for each result-row returned, I instantiate a new class Object where I use the Class' default constructor to set the instance variables. (I really wish there was a method like PHP's mysql-fetch-object()?)
I can then add each of these objects to say, a List(of Customer) and return it.
This doesn't seem like the best way to do it. If I were to change the Database schema, I'd have to reflect those changes in the class also.
View 1 Replies
ADVERTISEMENT
Oct 13, 2011
Basically I have the follwing:Dim ctx As New AdminCoreEntities Dim roles = (From r In ctx.Roles where r.Name.StartsWith("cust") Select r) 'list of System .Linq.IQueryable(Of AdminCoreModel.Role)
[code]...
The error i get when i run this is: Unable to cast object of type System.Data.Objects.ObjectQuery`1[AdminCoreModel.Role] to type AdminCoreModel.Role
Basically I have a many to many situation and I try to get all the Quicklinks objects queried by their roles and not quite sure why EF will cast to a single AdminCoreModel.Role when i.Roles is a collections of objects.
View 1 Replies
Feb 23, 2009
I'm trying to wrap my head about how to properly implement an OOP design for business objects that:
Have a "master list" in a database (ex. classifications)Are a part of another object as a property (i.e. object composition) but with additional properties
Here is where I'm stuck on the theory. Suppose that I have a Classification object, inheriting from the abstract class BusinessObject with the CRUD functions defined (MustOverride). This will give me:
[Code]...
What kind of other design could I implement here? It's obvous that I'm designing this the wrong way, but I don't see an easy alternative pattern. I don't want to repeat the code in the CustomerClassification class by not inheriting Classification and repeating all the field and property code, but I also don't want to expost CRUD functions to the CustomerClassification level. What am I missing in looking at the overall class design?
EDIT: Saving the classification level to the database will be handled by the customer object, because the database is legacy and the field for Level is defined in the customer table.
View 2 Replies
Jan 15, 2010
I have a Page class and a PageCollection class in a 3d party ORM framework. I can fill the PageCollection based on parameters (pageid, parentid, url etc..) (SQL query). But I need the data multiple times around the ASP.NET MVC website (Sitemap, Authentication), so I chose to load all pages 1 time and reference that (global) collection.
GlobalClass.Pages //is PageCollection containing all pages
I have now created functions which return a temporary subcollection or single entity based on the parameters mentioned before (pageid, parentid, url etc..).
GlobalClass.Pages.GetByPageId(id) //returns single page entity
GlobalClass.Pages.GetByParentId(parentid) //returns subcollection
The site however got very slow.
cache the subcollections (GetByParent())? create internal hash-lookup tables for the collection? Something else...?
Namespace BLL
Public Class PageCollection
Inherits CustomCollectionBase
[Code]....
View 1 Replies
Jan 9, 2012
i am caching objects, if i make linq queries on cached entities then... will theses queries make database round trip due to lazy loading in Entity framework?
View 1 Replies
May 26, 2009
I've been working on a really large project for almost 2 years and the client requirements keep changing. These changes, of course, effect everything and I would like to find a way to work with the CSS in a more dynamic fashion.
I assume I could get one of the ruby or python CSS DSLs running under ironRuby/Python but this client is very very particular about what software/frameworks are installed.[url]...
View 3 Replies
Feb 28, 2011
In my applications I use objects and classes, but when reading SO topics, I have the idea I don't use real OOP principles. For example, I never use inheritance or interfaces. Therefore, I am trying to learn proper OOP (in VB.NET), but I find some concepts quite hard to understand (even after reading a lot about the subjects on SO).So I'm trying to find a book or resource with good practical real-world examples. For instance, I kind of understand examples like using an interface for both Dog and Cat classes when using a EatFood method, but I find it hard to relate it to real-world cases.Ideally these books or resources should cover explanations about:
- when and why to use inheritance or interfaces or abstract classes
- when and why to use private, public, protected, virtual etc.
- best practices in dependency injection /inversion of control
- when to use aspect oriented programming
- using of constructors
- solid principles
- singletons
- encapsulation
Perhaps it's a mix of all kinds of concepts, but I think these are all related to OOP, please correct me if I'm wrong.I would prefer a book/resource with VB.NET examples, but this might be difficult?
View 3 Replies
Mar 8, 2010
Can you define this :
Class
Object
Inheritance
Polymorphism
Abstraction
And could you make it easy to understand I'm having a hard time to understand those terms.
View 7 Replies
Jun 22, 2010
making a log in form for administrator using the accounts from the MySql database .. i want to know the code in connecting database, because i am new in SQl database Programming.. xample there are 2 fields in SQL database the Username and Password.. the elements inside the field Username is admin and in Password is asusTek. how can i trigger the user if he enter in the wrong Username and Password in two textbox in the form .... I am Using Visual Studio 2005 and my SQL is SQLExpress Edition with SQL server 2005
View 1 Replies
Mar 2, 2012
I don't know if this is even the correct terminology but I was wondering if it is possible to bind a row (of data) from a database to an object. I am working on a school project and we have decided to create this application to track a user's BMI/BMR and compare it to the amount of calories they have input. The program doesn't go too in depth so it does not store the calories consumed in the database.
So here is my problem. I have a row in my database:
First_Name -- Last_Name -- Height_Inches -- Weight_Pounds
And I guess what I am thinking I want my program to do is if I have an object with properties for FirstName, LastName, HeightInches, WeightPounds, is to somehow query the database for one row and put the values into the object. All we have learned so far is binding the data with controls which doesn't really help in my case since the work is going to be done behind the scenes.
View 1 Replies
Jun 2, 2009
in terms of speed and resource usage is it better to call the access queries using access.aplication or rewriting the database objects in VS? By using access there should be just one version of the queries, not two and access is more friendly for writing the queries.
View 2 Replies
May 16, 2010
Private Sub btnPurchase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPurchase.Click
Dim objCustomer As Customer
Dim objProduct As Products
Try
[code]...
1- why not just write queries those manipulate the database rather then creating objects, making changes and then going back to database.
2- now that i have got the new balance and the product oder has been made so every time this happens a query has to be sent to change database or there is any other better why of doing it?
View 1 Replies
Jun 16, 2010
I have a connection string set up and a data reader.I have two textboxes on my form for users to type in. One textbox (txtLogin) is a user name and the other textbox is a password (txtPwd). I'm trying to compare what a user types into those two boxes to a table in a vfp database. The table I'm trying to compare to is open about 99% of the time so I need to be able to read from it in some type of "shared" mode.
My Select statement needs to be something similar to "select * from sites where clogin = txtLogin.text and cpassword = txtPwd.text"I just don't know how to get this to work properly.
View 2 Replies
Jun 9, 2011
I have decided I would start small and make a program that would create a "receipt" list in a listbox and a total. Now, I would like the user to be able to add their own "menu" items. I'm assuming the best way to go about this would be to have them actually add it to a database and then a function in the program will refresh the dataset with the new list. However, this is where my problem lies. How can I tell VB .net 2010 that I want to create a new button (or buttons) on the fly, in an orderly pattern on the form, based on the input from a DB?
View 10 Replies
Jul 8, 2009
How can we use the database objects from one form to another? Eg. In my Login form a person enters his user-name and password & if it is correct, the code directs him to another form(Form2). Now in Form2 How will I get which person has entered in?
View 1 Replies
Jan 8, 2010
I have developed a small window application, having lot of insert and select scripts. It runs fine for 3 times but when i run it 4th time it gives me Error "Out Of Memory Exception". I observed that in my task manager Sqlserver.exe process occupies memory around 167000K. Then I killed it. and again run the code, this time it occupy 12000K memory. Again I run it...the memory increases and stops at 87125K. All It means i the C#.net objets are not disposed well.
I have tried for
GC.GetTotalMemory()
But failed? How can I release objects?
View 8 Replies
Oct 11, 2009
I opened vs 2008 and used the server explorer for the first time to create a connection to my SQL 2005 db. The solution explorer pulled in all the tables, the database diagram etc. My question is how do I access that database connection and work with it using ADO objects? Do I need a reference to ADO?
View 4 Replies
Oct 5, 2009
I have a problem with access database in my vb project. I would like to fill the listbox with objects from my database. I've attached two images. In first image when i'm using command objDataAdapter.Fill(mydataset....) i can select table property(zaposlen). But in second image or in my second app i dont have an option to select table property in my dataset(there is nothing to select). If i select DataTableDataTable i get next error: DataTableDataTable' is a type in 'WindowsApplication1.baza_podatkovDataSet' and cannot be used as an expression.
View 2 Replies
Apr 9, 2010
I have this code that creates a template and stores that template to a local database and I want it also to store in a network database but I'm having problems on the other end it seems it's not storing the right data.
Server side
Dim cnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=|DataDirectory|fp.mdb; Jet OLEDB:Database Password = joceradmin"
Dim fpFilename As String
Dim userID As String
userID = InputBox("Please enter ID number to enroll", "Enter ID Number", , 100, 100)
[Code] .....
View 2 Replies
Mar 3, 2010
I am using VB Exopress 2008 and SQl Server Express 2008 in Windows Vista Home Premium. I have created a dataset after importing all tables and queries from MS Access to SQL Server. I have now added a view in SQL Server that I want to access and use in VB Express. However on clicking "Refresh" for the dataset the new view does not display in the available objects, only those I originally imported and opened with the original dataset. What, pleas am I doing wrong? How can I see this new View?
View 3 Replies
Dec 21, 2011
I am quite new to VB and have a Problem. I need to step through all IE entities and extract the html source of a tab where some conditions are met.
Private Sub TabPage1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabValues.Click, TabPage1.Enter, TabPage2.Enter
Dim err = "", status As String = ""
[code].....
View 1 Replies
Sep 26, 2010
We've got the following scenario:
Central Database (replicated across multiple servers)
Client Database 1
Client Database 2
The Central db has Users and Roles amongst other things The Client dbs have similar tables to each other but with some fields tweaked - contact, address, At present, each client db has its own user/role information which is copied from the central db by a scheduled process. I want to retrieve the user/role information directly from the central db instead (bearing in mind tables in the client db make reference to the user entity)
View 1 Replies
Apr 23, 2009
Given two tables, customer and orders, how would one do a linq query to entities to find any customers with open invoices started before a certain date?
View 1 Replies
Nov 15, 2011
I am just digging into L2Sql and I am a little confused on what to do about inserting several records into my database that are related.
For example:
I have an entity mapped to a user table called user. This class contains UserId and Username.
I have an entity mapped to a preference table called preference. This class contains PrefId, PrefName, UserId.
I have an entity mapped to a profile table called profile. This class contains ProId, ProName, UserId.
When I ask a user to register for an account, this will populate a User object. I will then create two "blank" objects to relate to this user, a profile and a preference.
I notice that the dbml has a User property on both the profile and prefernce entities. Am I right in thinking that if I pass the User object to this property, this in turn sets the UserId for these objects?
If thats the case, when do I actually do this? Surely I would need to InsertOnSubmit the user object, query it back to get the Id and then pass this User object to the others before Inserting them?
At the moment I have this,
Dim reg As New User
reg.Username = username
Dim pro As New Profile
[Code]....
View 5 Replies
Aug 9, 2010
I have a simple XML file like so:
<?xml version="1.0" encoding="UTF-8"?>
<foo attr="blah ° blah"/>
When I load it into the .NET XmlDocument and issue a Save, i.e.:
xmlDoc = New XmlDocument()
xmlDoc.Load("c: empar.xml")
xmlDoc.Save("c: empad.xml")
the new XML file contains the resolved amp 176 (a degree sign). This then breaks the final black box I'm trying to load the XML into. I've tried playing with the encoding, to little effect. Is it possible for the parser to just echo what came in, without resolving the entities? Inerestingly, it doesn't resolve &#176;
View 1 Replies
Dec 5, 2011
make objects from the ToolBox using code instead of changing existing objects invisible then visible later?
View 7 Replies
Jun 23, 2012
I am getting this error, Not sure why it is happening "Error The SqlParameterCollection only accepts non-null SqlParameter type objects, not Int32 objects."I have tried with all sorts of possibilties, now try to enter default data as dummy data,
Using connection As New SqlConnection
connection.ConnectionString = ConfigurationManager.ConnectionStrings("DentalDeviceConnectionString").ConnectionString
connection.Open()[code].....
View 1 Replies
Jan 29, 2011
I have a program like this.
Module Module1
Public Class Mstr
Public Property Prop1 As String
Public Property Prop2 As String[code]....
But it is not working as I expect it to. You can see it from.The DtlsB properties of all three DtlsA objects are having values from last iteration.
View 1 Replies
Jan 6, 2011
I want to let the user input objects to a richtextbox 1 object on each line, and somehow use Random.Next to select pseudorandomly a few objects, the number 'few' inputted in a textbox.
View 9 Replies
Jan 18, 2012
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Using conn As New SqlConnection("Database=Clinic_Management_System;Data Source=.SQLExpress;Integrated Security=True;AttachDBFilename=|DataDirectory|Clinic Management System.mdf")
Dim cmdRecord As SqlCommand
[code]....
View 2 Replies