我想,我理解它並且不會有問題。但現在我很困惑。我有以下代碼:'只支持原始類型,枚舉類型和實體類型'
public class ProjectMemberUserRolesElementViewModel
{
public string AccessType { get; set; }
public bool Delete { get; set; }
public bool Create { get; set; }
public bool Edit { get; set; }
public bool Read { get; set; }
}
var elements = from i in db.ProjectAccessTypes
select new ProjectMemberUserRolesElementViewModel()
{
AccessType = i.Type,
Create = (i.ProjectMemberAccess.Where(p => p.ProjectMemberID == ProjectMemberID) != null) ? (from p in i.ProjectMemberAccess where p.ProjectMemberID == ProjectMemberID select p.Create).FirstOrDefault() : false,
Delete = (i.ProjectMemberAccess.Where(p => p.ProjectMemberID == ProjectMemberID) != null) ? i.ProjectMemberAccess.Where(p => p.ProjectMemberID == ProjectMemberID).Select(p => p.Delete).FirstOrDefault() : false,
Edit = (i.ProjectMemberAccess.Where(p => p.ProjectMemberID == ProjectMemberID) != null) ? i.ProjectMemberAccess.Where(p => p.ProjectMemberID == ProjectMemberID).Select(p => p.Edit).FirstOrDefault() : false,
Read = (i.ProjectMemberAccess.Where(p => p.ProjectMemberID == ProjectMemberID) != null) ? i.ProjectMemberAccess.Where(p => p.ProjectMemberID == ProjectMemberID).Select(p => p.Read).FirstOrDefault() : false
};
爲什麼我得到這個錯誤?這裏的原始類型不在哪裏?
您可以替換'X? x:false' with'x ??假' – SLaks
錯誤運算符'??'不能應用於類型'bool'和'bool'的操作數\t;) –
將'p.Delete'轉換爲'bool?'。然而,'bool'的默認值是'false',所以你完全不需要這個。 – SLaks