[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 638
  • Last Modified:

Entity Framework, LINQ: Select Data from tables, crosstables and parenttables

Hi experts

I'm new to this stuff.
I have the following model:
Cocktail 1--m RecipeEntries mc--1 Ingredients

Now I have a CocktailRepository and a Cocktail-Entity.
I need to get all my data for a cocktail, which includes of cource the recipe entries and the ingredients (the name of the ingredients).

But how can I do that, it's easy to select Cocktail and its related RecipeEntries but how do I get the Ingredients?
Should I even do that I one query or not?

I'm using EF4, .NET 4 and C#
  • 4
  • 2
1 Solution
Please post the details about entities with foriegn keys/relationships.

ArikaelAuthor Commented:

I attached a screenshot of the model (comments is not important) Model of the entities
you do join
like this sample:
var t = from p in BlogBLL.Posts

            join cp in BlogBLL.CategoryPosts on p.PostId equals cp.PostId

            join c in BlogBLL.Categories on cp.CategoryID equals c.CategoryID

            select new


                PostId = p.PostId,

                CategoryName = c.CategoryName,

                PostName = p.PostName,

                PostSubName = p.PostSubName            


Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

ArikaelAuthor Commented:
thanks, so joins are the only way to do that?
or does it even make sense to do it in one query?
yes 'joins'
the sample very similar to your solution.
 EF4 will translate to SQL statement query that also joins...
check this too:
EF4 LINQ Ordering Parent and all child collections with Eager Loading

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now