Linq-to-entities join 3 tables and group-by statement?

You didn't mention which version of EF you are using, or whether you need to filter the authors by some condition, or filter the books by some condition. A general query that will fetch everything will look like this: List authorsWithBooks = context. Authors.

Include(a => a. Books). // For EF 4.1 /*Include("Books").

Instead for previous versions of EF */ /*Where(a =>!a. IsDeleted). If you want to filter the authors */ ToList() If you want to filter the book collections, you will have to write a more elaborate query though.

You didn't mention which version of EF you are using, or whether you need to filter the authors by some condition, or filter the books by some condition. A general query that will fetch everything will look like this: List authorsWithBooks = context. Authors.

Include(a => a. Books). // For EF 4.1 /*Include("Books").

Instead for previous versions of EF */ /*Where(a =>!a. IsDeleted). If you want to filter the authors */ ToList(); If you want to filter the book collections, you will have to write a more elaborate query though.

I have a technical difficulty -- perhaps because I apply code-first(?) -- to get your approach to work in my case, but I’m inclined to believe the Include method may be responsible for the grouping trick. – user669226 Jun 13 at 3:53 @Yakimich :: How do you control ordering of author names and book titles? – user669226 Jun 13 at 9:37 To order the authors you add OrderBy(a => a.Name) after the Include.

Ordering the books is more of a challenge, though. Are you using EF 4.1? – Yakimych Jun 13 at 10:14.

Var query = (from customer in MyDataContext. Aurthor select author) . Including(author=> author.

Books); This will get you all the authors and eager load the books for best performance.

I need a linq-to-entities statement that will retrieve authors and their respective books grouped by author. An additional constraint is the oject of grouped items has to be returnable by a method. Can anybody formulate join and group-by statement (a) ordered by author name, (b) ordered by author name and book title?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions