skyrunner
skyrunner

Reputation: 500

LINQ join with multiple conditions of different kind

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?

Upvotes: 2

Views: 98

Answers (2)

Mukesh Kalgude
Mukesh Kalgude

Reputation: 4844

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 };

Upvotes: 0

Aducci
Aducci

Reputation: 26634

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 };

Upvotes: 3

Related Questions