我正在尝试优化查询,因此将其插入 LINQPAD 但我不断收到空引用错误,无法将空值分配给 System.Int32 .. 当我在最后注释掉 FolderID 时,错误没有发生时间更长。为什么它假定 FolderID 是 System.Int32,我怎样才能使它成为 Int32?相反,它可以为空,我可以运行查询?
(from groupBundle in GroupBundles
join userGroup in UserGroups on groupBundle.GroupID equals userGroup.GroupID
join bundle in Bundles on groupBundle.BundleID equals bundle.BundleID
where userGroup.UserID == 75
orderby bundle.BundleName
select new
{
BundleID = bundle.BundleID,
BundleName = bundle.BundleName,
BundleIcon = bundle.BundleIcon,
UseSpecialPlayer = (bundle.UseSpecialPlayer != null && bundle.UseSpecialPlayer == true) ? true : false,
height = bundle.PuHeight,
width = bundle.PuWidth,
UserID = 75,
CompanyID = 32,
IsFavorite = ((from f in Favorites where f.FavoriteTypeID == 1 && f.UserID == 75 && f.ActionID == bundle.BundleID select f).Count() > 0) ? true : false,
//THIS ONE HERE
FolderID = (from cf in CategoryFolders
join folder in Folders on cf.FolderID equals folder.FolderID
where folder.CompanyID == 32 &&
cf.CategoryID == bundle.BundleID
select cf.FolderID).FirstOrDefault()
}).Distinct()