0
以下作品查詢:兩個看似相同的LINQ查詢。一件作品,其他沒有
var result = (from p in db.Permissions
join z in db.PermissionOverridesByUsers on p.id equals z.PermissionID into x
from y in x.DefaultIfEmpty()
where userRoleIds.Contains((Guid)(p.ParentRoleID))
select new RolePermissionViewModel
{
id = p.id,
Name = p.Name,
IsSet = ((y.id != null && y.id > 0) ? false : true)
}).ToList(); // If an exception exists, IsSet = false, otherwise = true.
這一項上IsSet
var query1 = (from p in db.Permissions
where userRoleIds.Contains((Guid)(p.ParentRoleID))
select p).ToList();
var query2 = (from ov in db.PermissionOverridesByUsers
where ov.AffectedUserID == id
select ov).ToList();
var result = (from q1 in query1
join z in query2 on q1.id equals z.PermissionID into x
from y in x.DefaultIfEmpty()
select new RolePermissionViewModel
{
id = q1.id,
Name = q1.Name,
IsSet = ((y.id != null && y.id > 0) ? false : true)
}).ToList();
產生一個空引用錯誤我在做什麼錯?我怎樣才能讓第二個結果工作?
工作很好。非常感謝你! – Ryan 2014-10-03 01:51:51