2

I am surprised I cannot find a solution for this on the web, but wording the search terms was a bit difficult. The question I have is about generating entity SQL that only returns the needed columns in a group join using Lambda syntax.

The following is a "toy" example. I am not joining on two entities, rather on an enumerated list and an entity. And tunnelling is not an acceptable answer. I need to apply this to a much larger problem using a group join and select many.

var result1 = clientprofiles.Join(Context.Adjusters,
c => c.AdjusterId,
a => a.AdjusterId,
(c, a) => new {a.ClientAccountId}).ToList();

Using Julie Lehrman's Entity profiler, I see that the query is being generated to select every record in the rows that meet the join criteria. How do I pare it down so it only selects the ClientAccountId field in this example?

Frank M
  • 523
  • 1
  • 4
  • 20

1 Answers1

1

You can project a set of columns on any select from the context, so in your case you can constrain the Context.Adjusters parameter by using

Context.Adjusters.Select(a=> new { a.ClientAccountId })

to constrain the query to just the single column

Steve Mitcham
  • 5,268
  • 1
  • 28
  • 56