我想做一个加入,但我需要比较一个简单的密钥。例如,我想做类似以下的事情:
from a in tableA
join b in tableB on a.x between b.minX and b.maxX
不是很复杂。但是Join lambda方法的函数似乎想要一个简单的密钥来进行比较。
有什么想法吗?
答案 0 :(得分:2)
from a in tableA
from b in tableB
where a >= b.minX && a <= b.maxX
select a;
答案 1 :(得分:0)
这样的东西?
var fdts = from fdt in context.FeuilleDeTemps.Include("FeuilleDeTempsJournees")
where
(employes.Contains(fdt.ID_Employe)) &&
(fdt.DateDepart <= date) &&
(fdt.DateFin >= date)
orderby fdt.ID_Employe
select fdt;
或在你的情况下
var v = from a in context.tableA.Include("tableB")
where
a.x < b.minX &&
a.x > b.maxX
select v;
答案 2 :(得分:0)
您是否专门询问了虚线语法?
var tableA = new[] {1, 2, 3, 4};
var tableB = new[]
{
new {minX = 1, maxX = 2},
new {minX = 3, maxX = 6},
new {minX = 5, maxX = 7},
new {minX = 6, maxX = 8},
};
var res = tableA.SelectMany(a => tableB, (a, b) => new {a, b}).Where(t => t.a >= t.b.minX && t.a <= t.b.maxX)
.Select(t => t.a);