有人可以解释为什么这不起作用。
private void AdditionalLoad(List<PersonTypePerson> ptps)
{
using(var _context = new SPIS_Entities())
{
var m = (from ptp in ptps.Where(xx => xx.PersonID == _Person.ID)//_context.PersonTypePerson //
join pt in _context.PersonType on ptp.PersonTypeID equals pt.ID
join pta in _context.PersonTypeAttriubute.Where(p => p.active) on pt.ID equals pta.PersontypeID
select new { persontypeatribute = pta, availableatribute = pta.Attribute }).ToList();
var x = from ii in _context.InformationItem.Where(p=>p.PersonID ==_Person.ID)
join pta in _context.PersonTypeAttriubute.Where(p => p.active) on ii.PersonTypeAtributeID equals pta.ID
select new { persontype = pta.PersonType, attribute = pta.Attribute, information = ii };
var z = (from all in m
join fill in x on all.persontypeatribute.AttributeID equals fill.attribute.ID into ps
from fill in ps.DefaultIfEmpty()
select new
{
persontype = all.persontypeatribute.PersonType, //fill.persontype,
available = all.availableatribute,
attribute = fill.attribute,
information = fill.information
}).ToList();
}
}
最有趣的是我从“m”和“x”获得查询结果。当涉及到使左连接(“z”)的点时,它会中断并抛出nullException,对象引用未设置为对象的实例。