-1

Could you tell me how transform the query below to Linq Method version :

 myResult =
    from table1 in db.TABLE1
    join table2 in db.TABLE2 on table1.TABLE2_ID equals table2.ID
    join table3 in db.TABLE3 on table1.TABLE3_ID equals table3.ID
    where table1.ACTIF == true
    select new MyClass
    {
         T1MyField1 = table1.MyField1,
         T1MyField2 = table1.MyField2,
         T2MyField1 = table2.MyField1,
         T2MyField2 = table2.MyField2,
         T3MyField1 = table3.MyField1,
         T3MyField2 = table3.MyField2,
         T3MyField3 = table3.MyField3
    }

Update 1: I created a predicate :

 Expression<Func<IMyClass, bool>> predicate;

And I'd like apply it the the lambada but I think it's not possible with lambda syntax.

4

3 回答 3

1

您可以使用ILSpy将带有查询语法的当前程序集反编译为方法语法查询。只需转到选项,然后取消选择“反编译查询表达式”。

于 2012-08-20T11:46:11.313 回答
1
var myResult = db.TABLE1
    .Join(db.TABLE2, t1 => t1.TABLE2_ID, t2 => t2.ID, (t1, t2) => new { Table1 = t1, Table2 = t2 })
    .Join(db.TABLE3, j => j.Table1.TABLE3_ID, t3 => t3.ID, (j, t3) => new { Table1 = j.Table1, Table3 = j.Table2, Table3 = t3 })
    .Where(row => row.Table1.ACTIF)
    .Select(row => new MyClass {
        T1MyField1 = row.Table1.MyField1,
        T1MyField2 = row.Table1.MyField2,
        T2MyField1 = row.Table2.MyField1,
        ...

    });
于 2012-08-20T11:53:37.690 回答
0

关于您的编辑:您可以随时混合使用两种样式:

myResult = (from ... select new MyClass { ... }).Where(predicate);
于 2012-08-20T11:55:03.413 回答