I have a Human entity that has an EntitySet property containing Pet entities. I want to select all humans + a string concatenation of their pet's names. For example:

from human in session.Query.All<Human>()
select new {
   Id = human.Id,
   Name = human.Name,
   PetNames = human.Pets.Select(pet => pet.Name)

Then I print string.Join(", ", human.PetNames).

Unfortunately, this causes many queries (1 to query all humans, then 1 query to fetch each pet's name). I'd like all of this done in 1 query.

I can't include the string.Join() in the initial projection, because the LINQ translator doesn't support it. Can I write a custom translator for it? Any guidance you can provide?

Thank you!

asked Jan 10 '12 at 22:40

ara's gravatar image


edited Jan 10 '12 at 22:48

One Answer:

Hello Ara,

I think, this is a nice case to utilize the power of Prefetch feature. For more information and examples see the corresponding section of the manual.

Hope that helps.

answered Jan 11 '12 at 02:05

Dmitri%20Maximov's gravatar image

Dmitri Maximov

Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview


Once you sign in you will be able to subscribe for any updates here



Asked: Jan 10 '12 at 22:40

Seen: 4,511 times

Last updated: Jan 11 '12 at 02:05

powered by OSQA