我有以下查询,我没有实现,它有两个不同的表左连接
SELECT p.FirstName, p.LastName, u.UserName FROM
[APT2016_WEBDATA].[dbo].AspNetProfile p
LEFT JOIN [APT2016_WEBDATA].[dbo].AspNetUsers u
ON p.UserId = u.Id
LEFT JOIN [APT2016_PFDATA].[dbo].[PF_Member] pf
ON p.MemberId = pf.MemberUID
WHERE pf.MemberUID IS NULL AND (p.FirstName IS NOT NULL OR p.LastName IS NOT NULL)
它会返回正确的4300
结果,但是当我将其实现到实体框架中时,它会返回29000+
个结果,并带有以下代码
var result = (from p in AspNetProfiles
join u in AspNetUsers on p.MemberId equals u.MemberUID
join m in PF_Member on p.MemberId equals m.MemberUID into msp
from pfm in msp.DefaultIfEmpty()
where pfm == null && (p.FirstName != null || p.LastName != null)
//where msp.FirstOrDefault() == null
select new UsersWithoutMemberViewModel
{
UserName = "",
FirstName = p.FirstName,
LastName = p.LastName
}).ToList();
有人可以帮我解决问题
更新
如果我删除带有join
表的AspNetUsers
,它将返回所需的正确数据量,但在这种情况下,我将丢失我将从此UserName
获取的数据join
1}}