LINQ: querying multiple entities

M

MCohen75

I have a couple entities setup with associations. A ReleasePackage has many
Conent entities. For the ReleasePackages in the list, I want to get all
Conent entities. This is like a simple join, here's the code:

IList<Content> contentList =
(from p in this.ReleasePackage
from c in p.Content
select c).ToList<Content>();

For some reason this doesn't work, I get zero results in the list.

I did call Load on the ReleasePackage (which is an association from another
entity) prior to the statement above.

If I manually iterate over the ReleasePackage entities and access the
Content association on each, I get the correct records.

What gives?

--Mike
 
M

Michael Cohen

It looks like I have to explicitly load each association. If i iterate over
the list of release packages and load the associations to Content, the
statement below works.

With EF can I specify that I want to automatically load some associations?

--Mike
 
F

Frans Bouma [C# MVP]

MCohen75 said:
I have a couple entities setup with associations. A ReleasePackage has many
Conent entities. For the ReleasePackages in the list, I want to get all
Conent entities. This is like a simple join, here's the code:

IList<Content> contentList =
(from p in this.ReleasePackage
from c in p.Content
select c).ToList<Content>();

For some reason this doesn't work, I get zero results in the list.

I did call Load on the ReleasePackage (which is an association from another
entity) prior to the statement above.

If I manually iterate over the ReleasePackage entities and access the
Content association on each, I get the correct records.

If this is linq to sql, you should look into LoadOptions to tell linq
to sql to load associated entities as well. It's only efficient 1 level
deep.

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top