C# 组合查询
我使用LINQtoSQL获得两个列表,而不是与另一个列表合并。他们工作得很好。但我想知道是否可以在一个或两个查询中完成,而不是我已有的三个查询 查询是C# 组合查询,c#,linq,tsql,linq-to-sql,C#,Linq,Tsql,Linq To Sql,我使用LINQtoSQL获得两个列表,而不是与另一个列表合并。他们工作得很好。但我想知道是否可以在一个或两个查询中完成,而不是我已有的三个查询 查询是 var l = (from t in T_list1 where t.Date == DateTime.Today select new { oldDate=t.OldDate, Name=t.name,
var l = (from t in T_list1
where t.Date == DateTime.Today
select new
{
oldDate=t.OldDate,
Name=t.name,
Email=t.EmailAddress,
list2TableId=t.l2Id,
CustomerId=t.customerId
});
var l2=(from d in T_list2
from e in l1
where d.Id == e.list2TableId
select new
{
Date=d.oldDate,
CName=d.Name,
Experience=e.experience,
});
list2.Dump();
var l3 = list2.Union(list3).ToList();
我正在看这篇文章,但没有工作。
感谢您的输入。您可以执行一个连接,而不是两个查询:
var l = (from t in T_list1
join d in T_list2 on t.l2Id equals d.Id
where t.Date == DateTime.Today
select new
{
oldDate=t.OldDate,
Name=t.name,
Email=t.EmailAddress,
list2TableId=t.l2Id,
CustomerId=t.customerId
Date=d.oldDate,
CName=d.Name
Experience=e.experience,
});
我还没有测试过这个查询,但它应该会告诉你大致的想法
查看SQL&Linq中的连接以获取更多信息。您的代码有什么问题,为什么要更改?我怀疑有一些拼写错误,但发布的代码没有什么意义。请检查l/l1/list1和l2/list2