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

x
  • 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#
0
Arikael
Asked:
Arikael
  • 4
  • 2
1 Solution
 
dj_alikCommented:
Please post the details about entities with foriegn keys/relationships.


0
 
ArikaelAuthor Commented:
Hi

I attached a screenshot of the model (comments is not important) Model of the entities
0
 
dj_alikCommented:
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            

            };

0
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?
0
 
dj_alikCommented:
yes 'joins'
the sample very similar to your solution.
 EF4 will translate to SQL statement query that also joins...
0
 
dj_alikCommented:
check this too:
EF4 LINQ Ordering Parent and all child collections with Eager Loading
http://stackoverflow.com/questions/4156949/ef4-linq-ordering-parent-and-all-child-collections-with-eager-loading-include
0

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