1

I have two tables TABLE_A and TABLE_B which are related.

I need to convert this SQL Server query to a LINQ lambda query in C#:

SELECT a.COL1, a.COL2, b.COL2
FROM TABLE_A a, TABLE_B b
WHERE b.COL1 = A.COL3

Actually b.col1 is pk in table_b and a.col3 is fk of that in table_a

5
  • 3
    Generally, a "please write my code for me" type of question is considered off-topic here. You should include your attempt(s) so users can help you improve on them. Commented Apr 30, 2018 at 17:01
  • Probably, these might help you stackoverflow.com/questions/17638625/… stackoverflow.com/questions/24197602/… stackoverflow.com/questions/3854146/… Commented Apr 30, 2018 at 17:01
  • @JacobH thank you for tip and respond ... but unfortunately in this case i have no idea how to start ..... im new in linq query ..i have done some things but not different cols from different tables Commented Apr 30, 2018 at 17:28
  • 2
    Perhaps start by reading my SQL to LINQ Recipe ? Commented Apr 30, 2018 at 17:44
  • @NetMage nice post Commented Apr 30, 2018 at 18:40

2 Answers 2

1

Navigation properties are powerful:

table_a.Select( a=> new {a.COL1 , a.COL2 , a.b.COL2} )

Also, you can learn how to write better questions at "How to create a Minimal, Complete, and Verifiable example" I suggest to you to read post carefully.

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

1 Comment

so how to define that a.b.col2 is for table_b and apply condition on col of table_b ... this is where i confused
0

var q = (from a in table_A join b in table_B on b.col1 equals a.col3 select new {a.COL1, a.COL2, b.COL2}).ToList();

1 Comment

OP asked for 'LINQ lambda query'

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.