【发布时间】:2020-03-25 08:45:56
【问题描述】:
是否可以在多个列上编写 lambda left join 来生成 OR 条件而不是 AND?
var query = context.table1.GroupJoin(
context.table2,
x => new { JoinCol1 = x.CustomerCode, JoinCol2 = x.CustomerName},
y => new { JoinCol1 = y.Code, JoinCol2 = y.Name},
(x, y) => new {
firstTable = x,
secondTable = y
}).SelectMany(
x => x.OrganizationAddress.DefaultIfEmpty(),
(x, y) => {
x.firstTable.field1,
x.firstTable.field2,
y.Field3,
y.Field4
}
)
这将生成以下查询
SELECT t1.filed1, t1.field2, t2.field3, t2.field4
FROM table1
LEFT JOIN table2 ON table1.CustomerCode = table2.Code
AND table1.CustomerName = table2.Name
我想获得相同的查询,但我希望它是 OR,而不是 AND 条件:
SELECT t1.filed1, t1.field2, t2.field3, t2.field4
FROM table1
LEFT JOIN table2 ON table1.CustomerCode = table2.Code
OR table1.CustomerName = table2.Name
有没有办法做到这一点?
编辑:版本 - EF 6.2.0
【问题讨论】:
-
EF6 还是 EF Core?版本?
-
@IvanStoev EF 6.2.0,我会将此信息添加到问题中。
标签: c# sql entity-framework