LINQ Join(左外)与 Take(1)
如果没有任何地址(内部连接),我有以下 LINQ 返回零。我如何使其成为外部联接,然后仅 Take(1)
?
var results = query.Join(
DB.tblAddresses.Where(t => t.AddressTypeID == 'm' || t.AddressTypeID == 'b').OrderByDescending(x => x.AddressTypeID),
p => p.PersonID,
a => a.PersonID,
(p, a) =>
new
{
p.PersonID,
p.LastName,
p.FirstName,
p.MiddleName,
p.SSN,
p.BirthDate,
p.DeathDate,
AddressLine1 = a.AddressLine1 ?? string.Empty
});
return results.CopyLinqToDataTable();
I have the below LINQ that is returning zero IF there aren't any Addresses(Inner Join). How would I make this an Outer Join and then only Take(1)
?
var results = query.Join(
DB.tblAddresses.Where(t => t.AddressTypeID == 'm' || t.AddressTypeID == 'b').OrderByDescending(x => x.AddressTypeID),
p => p.PersonID,
a => a.PersonID,
(p, a) =>
new
{
p.PersonID,
p.LastName,
p.FirstName,
p.MiddleName,
p.SSN,
p.BirthDate,
p.DeathDate,
AddressLine1 = a.AddressLine1 ?? string.Empty
});
return results.CopyLinqToDataTable();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 GroupJoin:
Use GroupJoin:
)
)
使用 DefaultIfEmpty。
看一下 http: //social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/b285be6a-3324-4b16-89cd-856190090701
Use DefaultIfEmpty.
Take a look at http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/b285be6a-3324-4b16-89cd-856190090701