【发布时间】:2015-02-28 02:05:57
【问题描述】:
这是我的 SQL 查询:
Select distinct * from tr.Table1
Left Outer join tr.Table2 on tr.Table1.ID = tr.Table2.ID
Left Outer join tr.Table3 on tr.Table2.AId= tr.Table3.ID
where tr.Table1.Deleted =1 and tr.Table1.Ready=1 and tr.Table1.Show=0
查询在 SQL 中运行并给出了预期的结果。这里的事情是我想要使用 LINQ 的等价物。我尝试了一些 LINQ 查询的变体,例如:
var query = from p in _ctx.Table1
join s in _ctx.Table2 on p.Id equals s.Id into bag1
from to in bag1.DefaultIfEmpty()
join tx in _ctx.Table3 on to.AId equals tx.Id into bag2
from ts in bag2.DefaultIfEmpty()
select new
{
ContactNo = to.Table1.ContactNo
};
但它始终不会返回所有字段值。有些返回为NULL。还尝试引用其他一些链接,但它们都专注于与父表连接,而我必须将其中一个连接表与另一个连接。所以我在这里,正在努力解决这个问题。
这是我现在得到的输出。有些值为空。该字段具有值,但由于某些连接问题,它们返回为NULL。
感谢您的指导。谢谢。
【问题讨论】:
标签: c# asp.net linq asp.net-mvc-4 sql-to-linq-conversion