如何选择必填列?

时间:2019-07-09 06:59:35

标签: c# sql

 var abc =
                from t1 in db.base3
                where db.base2.Any(t2 =>
                          db.base1.Any(t3 =>
                              t3.ed > startDate && t3.ed < endDate  && t3.request_id == t2.request_id
                        ) && t2.link_id == t1.PersonId
                )
                select t1;    

不仅不能同时从base3(t1)中选择列,而且不能同时从base1(t3)中选择列

1 个答案:

答案 0 :(得分:0)

对于像您这样的linq语句,t2 / t3属性在最高级别是“未知”的。您可能会看到一些类似于C#中的嵌套循环:

    foreach(var t1 in base3)
{
    // t1 is accessible here
    foreach(var t2 in base2)
    {
        // t1, t2 is accessible here
        foreach(var t3 in base1)
        {
            // t1, t2, t3 is accessible here
        }
    }
}

除此之外,base3-Properties和base1-Properties之间没有关系。如果您的Linq将对实体使用联接,则可以访问所有属性,例如:

    var abc = (from t1 in db.base3
    join t2 in db.base2 on t1.PersonId equals t2.link_id
    join t3 in db.base1 on t2.request_id equals t3.request_id
    where t3.ed < DateTime.Now && t3.request_id < 20
    select new {t1.PersonId, t3.ed});