Home > Software design >  Convert LINQ query to SQL
Convert LINQ query to SQL

Time:02-24

var list = (from t1 in table1 ✓

join t2 in table2 on t1.xyz equals t2.abc ✓

join t3 in table3 on new { t1.abc , t2.qwe} equals new { t3.abc , t3.qwe}

select new Table
{

XYZ= t1.xyz,

ABC = t1.abc,

 QWE= t3.qwe

}).Distinct().ToList();

I want to convert this C# LINQ query to SQL query.

join t3 in table3 on new { t1.abc , t2.qwe} equals new { t3.abc , t3.qwe}

I couldn't convert after this part. Is there anyone who can help me?

CodePudding user response:

This could be your desired SQL Query

SELECT  DISTINCT t1.xyz AS XYZ, t1.abc AS ABC, t3.qwe AS QWE
FROM    table1 t1
JOIN    table2 t2 ON t1.xyz = t2.abc
JOIN    table3 t3 ON t1.abc = t3.abc AND t2.qwe = t3.qwe

CodePudding user response:

Here:

Select distinct t1.xyz as XYZ, t1.abc as ABC, t3.qwe as QWE 
from table1 as t1  
inner join table2 as t2 on t1.xyz = t2.abc 
inner join table3 as t3 on t1.abc = t3.abc and t2.qwe = t3.qwe
  • Related