I’m new to designing database stuff hands on, and rather than use new features like Linq to Entities code first, I’d like to implement the lower level stuff myself.
If I had a class Foo, which can contain any other number of Foos, it may look something like this:
class Foo
{
int FooId;
List<Foo> containedFoos;
...
}
Suppose the Foo table looks like
FooId, FooName, ContainingFooId (Foreign key to same table)
If I used code first and retrieved all my Foos, their containedFoos list would be automatically populated for me.
My question is, is this done on the applicaiton side (just do a straight select from the Foo table, and code the logic in C# to consruct a Foo, find all its containedFoo, build a list, etc)
or, is there way SQL Server can return the data in a more useful way? Such as returning each Foo and its contained items together in some way?
No, SQL Server won’t return the data like that. You would have to create your objects and populate them by hand to mimic the way Code First populates your objects.
This reason alone makes EF very attractive (to me) to use from the beginning of a project. It saves TONS of time.