Hi everyone,
I am having trouble with linq when it comes to objects that have a List / Array of sub objects attached to them. I understand the basics of linq to insert, update select and delete but only in the sense of each table is inderpendant of the others.
I think what I want to achieve is best explained in a senario...
Lets say we have our root object a "Bookcase" the Bookcase object in c# is represented as:
public class Bookcase
{
public Guid BookcaseID {get;set;}
public String BookcaseName {get;set;}
public List<Book> Books {get;set;}
public List<DVD> DVDs{get;set;}
public List<Magazine> Magazines {get;set;}
}
and a database table of:
FIELD NAME | DATATYPE
ID | UniqueIdentifier
BookcaseName | nvarchar(max)
then we have our Book, DVD and Magazine classes:
public class Book
{
public Guid BookID {get;set;}
public String Title {get;set;}
}
--------------------------------------------------------
FIELD NAME | DATATYPE
ID | UniqueIdentifier
Title | nvarchar(max)
________________________________________________________
public class DVD
{
public Guid DVDID {get;set;}
public String FilmTitle {get;set;}
public String Rating {get;set;}
}
--------------------------------------------------------
FIELD NAME | DATATYPE
ID | UniqueIdentifier
FilmTitle | nvarchar(max)
Rating | nvarchar(2)
________________________________________________________
public class Magazine
{
public Guid MagazineID {get;set;}
public int Issue {get;set;}
}
--------------------------------------------------------
FIELD NAME | DATATYPE
ID | UniqueIdentifier
Issue | int
Now if i want my total bookcase's current contence I have to query Bookcase for the ID, then query each other table in a seperate linq statement for Books, DVDs and Magazines...
Is there a way that i can query only the bookcase and get an already filled Bookcase object? or do I then have to do what I am doing and run 3 more queries as well and build the Bookcase object myself?
Thanks,
Xavier.