3

In C#, I need to retrieve a List<Object> using linq with lamba expression. This is the case:

List<TAB1> itemList = 
  context.TAB1.Join(
  context.TAB2, itm => itm.ItemCode, bcd => bcd.ItemCode, (itm, bcd) => new { ITM = itm, BCD = bcd })
                     .Where(i => i.ITM.ItemCode == (itemCode ?? i.ITM.ItemCode))
                     .Where(i => i.BCD.BcdCode.Contains(codeBars ?? i.BCD.BcdCode)).ToList();

At the moment that retrieves me a list<AnonymousType>, but I need a List<TAB1> that only return the values of that table.

EDIT: The returned List<TAB1> needs to replace one property (TAB1.Barcode) with TAB2.BcdCode (it's the same type). How can I do it?

1 Answer 1

4

Add Select statement after filters:

List<TAB1> itemList = 
  context.TAB1.Join(
  context.TAB2, itm => itm.ItemCode, bcd => bcd.ItemCode, (itm, bcd) => new { ITM = itm, BCD = bcd })
                     .Where(i => i.ITM.ItemCode == (itemCode ?? i.ITM.ItemCode))
                     .Where(i => i.BCD.BcdCode.Contains(codeBars ?? i.BCD.BcdCode))
.Select(i => i.ITM)
.ToList();
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, but I have a new question: If I want to replace one property of the TAB1 (TAB1.CodeBars) with one in TAB2 (TAB2.BcdCode), what I need to change in the select.

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.