2

I'm trying to translate following T-SQL query into LINQ:

SELECT * FROM table_A JOIN table_B ON table_A.key = table_B.key AND table_A.Trouble <> table_B.Trouble 

Stackoverflow is full with similar questions, but in my case there are two conditions but each of them has different operator ("equals to" and "not equals to"). Is there any way to get the same result using LINQ?

2

2 Answers 2

3

You can't use the join syntax, you have to use a where clause to connect the two

var query = from a in table_A from b in table_B where a.key = b.key && a.Trouble != b.Trouble select new { a, b }; 
Sign up to request clarification or add additional context in comments.

1 Comment

I think it doesn't compile in C# <> ;)
0

You can also write this query. It should be work fast

var query = from a in table_A from b in table_B.where(x=>x.key==a.key && x.Trouble != a.Trouble) select new { a, b }; 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.