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?

5
  • Looking at stackoverflow.com/questions/1531934/… could you try Context.Adjusters.Select(a=> new { a.ClientAccountId}) as your first argument to the join? Commented Feb 12, 2015 at 20:44
  • SELECT [Extent1].[AdjusterId] AS [AdjusterId] FROM [dbo].[Adjuster] AS [Extent1] ... worked perfectly. Commented Feb 12, 2015 at 20:54
  • Thanks Steve, not sure how to up vote you Commented Feb 12, 2015 at 20:56
  • Wrote it up as an answer. Wasn't sure originally. Commented Feb 12, 2015 at 20:57
  • Yeah, but great intuition. I kept trying to make a select below the join Commented Feb 12, 2015 at 21:00

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.