使用LINQ选择2个表

时间:2014-01-22 14:12:30

标签: c# linq

我有这样的查询:

var q2 = from i in dbconnect.tblComplementContracts
                 join b in dbconnect.tblContracts on i.contractId equals  b.contractId
                where (i.complementDate.Value - GetTime()).TotalDays <= _permission
                select i;

我想访问“i”和“b”字段,例如我尝试“选择i,b”但是它不起作用我该怎么办?

由于

1 个答案:

答案 0 :(得分:4)

您可以使用匿名类型:

var q2 = from i in dbconnect.tblComplementContracts
         join b in dbconnect.tblContracts on i.contractId equals  b.contractId
         where (i.complementDate.Value - GetTime()).TotalDays <= _permission
         select new { I = i, B = b};

foreach (var x in query)
{
    Console.WriteLine("complementDate:{0} contractId:{1}", 
        x.I.complementDate, x.B.contractId);
}