且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Linq to Entities - 子查询在where语句中

更新时间:2023-02-15 10:31:05

var r1 = 15;
var q = from t in Context.Table1
        where t.Reg1 == r1 && 
              t.Reg2 == Context.Table2
                               .Where(t2 => t2.Reg1 == r1)
                               .Max(t2 => t2.Reg2)
        select t;

如果您有从Table1到Table2的导航/关联,则更容易。但是你没有表现出来,所以我也不会....

Easier still if you have a navigation/association from Table1 to Table2. But you didn't show that, so neither will I....