0

我无法在 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 );
}
4

1 回答 1

2

用这个:

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使用延迟执行。

于 2013-01-15T13:01:17.877 回答