var query1 = from r in _residentRepository.GetAll()
join i in _inLogRepository.GetAll() on r.Id equals i.ResidentId into tmp_ir
from ir in tmp_ir.DefaultIfEmpty()
where r.Id == || r.Id ==
select new
{
resId = r.Id,
Id = ir.Id
};
var sum1 = query1.Count();
结果:左连接 一对多 没毛病
var query = from r in _residentRepository.GetAll()
join i in _inLogRepository.GetAll() on r.Id equals i.ResidentId into tmp_ir
from ir in tmp_ir.DefaultIfEmpty().Take()
where r.Id == || r.Id ==
select new
{
resId = r.Id,
Id = ir.Id
};
var sum = query.Count();
结果:左连接 一对一
.Take()方法
由此看出 使用.Take(1)方法在多表关联后可以实现与主表一对一的关系数据来;根据业务需要也实现特定N的条数。