c# - EF4 Linq - Get top items using criteria from related tables -


i have 3 tables need include in linq query in ef4. using dbcontext generator generate poco classes. linq query querying poco objects.

hopefully below explains how tables related in underlying database clearly.

orderdetails > - 1 books 1 - < bookcategories

as can see 1 book can have many categories , 1 book can appear on many orders.

i trying top selling books in specific category.

so far have managed top selling books overall below cannot seem extend include book category criteria in clause

var topsellingbooks = (from p in this.context.orderdetails                         p.issueid == issueid && p.publicationid != "4tc"                          group p p.bookid                         bookgroup                         select new                              {                                  bookno = bookgroup.key,                                  bookcount = bookgroup.sum(q => q.quantity)                              }).orderbydescending(q => q.bookcount)                               .take(noofbooks); 

using navigation properties, expected add

&& p.books.bookcategories.categoryid_fk=="mycatid" 

to criteria above not seem possible. cannot access properties of bookcategories using above.

is enough info see going on. got pointers?

thanks

wing

it seems problem loading strategy. need include related objects in query.

read eagerly , lazy loading, find lots of examples on page like:

var blogs = context.blogs                    .include(b => b.posts.select(p => p.comments))                    .tolist(); 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -