troubleshooting Question

Help with Linq Logic

Avatar of locdang
locdang asked on
.NET ProgrammingC#
3 Comments1 Solution345 ViewsLast Modified:
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.
ASKER CERTIFIED SOLUTION
dungla

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros