我不能得到下面的请求在Mono工作:没有连接,它将工作。当我只选择t1,它也工作,但我不能从两个表中选择的东西。我想我想要一个左连接,我总是在t1中有条目,如果NameOfFile匹配FileName,那么我想让表连接。
附加问题:我的查询何时执行?当我运行foreach循环时?
var result = (
from t1 in db.Table1
join t2 in db.Table2 on t1.FileName equals t2.NameOfFile
into joinDep
from t3 in joinDep.DefaultIfEmpty ()
select new
{
Time = t1.WriteTime,
Name = t2.NameOfFile
}
)
.OrderByDescending (c => c.Time.Date)
.Take (10);
foreach (var entry in result)
{
Console.WriteLine (entry.Name );
}
使用
var query = from t1 in db.Table1
join t2 in db.Table2 on t1.FileName equals t2.NameOfFile into gj
from joinDep in gj.DefaultIfEmpty ()
select new
{
Time = t1.WriteTime,
Name = joinDep.NameOfFile
};
var result = query.OrderByDescending (c => c.Time.Date)
.Take (10);
是的。Take
使用延迟执行。