首页 > 解决方案 > 如何制作 linq lambda 表达式

问题描述

select a.ObjectFieldID,
       a.FieldName,
       b.RelationName 
  from tblMNG_Framework_ObjectField as a left join 
       tblMNG_Framework_ObjectRelation as b on a.ObjectID = b.RelatedObjectID 
                                           and a.ObjectFieldID = b.RelatedKeyFieldID 
 where a.ObjectID = 2 
   and a.Deleted = 0

标签: c#sqlentity-frameworklinqlambda

解决方案


这是我的快速代码,我没有要测试的数据,所以如果左连接不准确,请向我反馈您的数据样本。

tblMNG_Framework_ObjectField.GroupJoin(tblMNG_Framework_ObjectRelation,
                a => new { JoinCol1 = a.ObjectID, JoinCol2 = a.ObjectFieldID },
                b => new { JoinCol1 = b.RelatedObjectID, JoinCol2 = b.RelatedKeyFieldID },
                (a, b) => new { a, b }).Where(x => x.a.ObjectID == 2 && x.a.Deleted == 0)
                .SelectMany(b => b.b.DefaultIfEmpty(),
                (a, b) => new { a.a.ObjectID, a.a.FieldName, b.RelationName });

希望能帮助到你


推荐阅读