Link to home
Start Free TrialLog in
Avatar of jlrray
jlrray

asked on

Classes & Databases

If i have a bunch of objects, from the class PERSON - i understand how to use it, save it to a database, etc...  Lets say I have a few thousand records of PERSON.  Is it better to bind it directly to a grid or better to pull them into classes and manually put them into the grid?
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Hi jlrray;

Seeming you placed this question into the thread of Language Integrated Query - LINQ are you using .Net Framework 3.X?
Are you using Linq to access the Database?
Are you using MS SQL Server?
How is the data from PERSON stored in the database?

Fernando
in my opinion, direct binding will be efficient and will take less time than populating collection of objects and then binding the populated collection with the grid.
Avatar of jlrray
jlrray

ASKER

1.  Yes, it is SQL Server
2.  I have not used LINQ for it, but am planning on it
3.  Originally the PERSON was saved to the database using SQL INSERT.

Previously, I always used a control that was data bound to a database.  For me, this just seems to create some pretty ugly work arounds.  I'm probably approaching this wrong.  For the most part, all of my objects are either PERSON or an ITEM of some sort.  You could probably think of it as more of an inventory style of database.

USMANR -- then if you were going to create a new entry, would you use the data bound control to enter directly to the database or would you create an object instance of a class and then push the whole thing to the database.

Joe
Are you using Visual Studio 2008, .Net Framework 3.X?
Avatar of jlrray

ASKER

Yes.  VS2008 & 3.5x

Joe
Hi jlrray;

Seeming you are planning to use Linq to SQL. When you add the DataContext / ORM and place a table from your database into the DataContext it will create a class that matches the structure of that table as a strongly type class into your project. You can use this class in place of the one already in your project. Then you can assign the collection of returned values directly to the data source of the data grid view.

Fernando
Avatar of jlrray

ASKER

I'm not exactly familiar with this, however, it seems to me that this will create ambiguous code.  Maybe I'm not understanding this correctly.  If I have a class say MAN which inherits from a PERSON, with properties usually associated with a Man and methods like DrinkBeer(), -- the DataContext will createa  pseudo class for me that matches the structure--- but what will it look like?  Will it be intuitive?  For instance, if I want to save the record or access the property -- how would I call it?

Joe
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial