作者:战地上尉 | 来源:互联网 | 2023-01-31 22:41
原因efcoregroupnewdynamic对象时生成int型而不是int?而导致Nullableobjectmusthaveavalue.解决:groupbynew一个具体的对
原因 efcore group new dynamic对象时生成int 型而不是 int? 而导致 Nullable object must have a value.
解决:group by new 一个具体的对象,并将int 类型设为可空
出错语句:
var queryC = from d in queryD
group d by d.PicId into g
select new
{
PicId= g.Key,
Count = g.Count()
};
var query = from r in queryR
join c in queryC on r.FId equals c.PicId into g
from cg in g.DefaultIfEmpty()
join s in _repository.GetAll() on r.FId equals s.PicId into k
from sk in k.DefaultIfEmpty()
select new RecordDto()
{
Type = r.Type,
Name = r.Name,
FId = r.FId,
IsDeleted = r.IsDeleted,
CreationTime = r.CreationTime,
Id = r.Id,
Status = sk != null ? sk.Status : false,
IdentityType = cg != null ? (cg.Count > 1 ? IdentityTypeEnum.多 : IdentityTypeEnum.单) : IdentityTypeEnum.无
};
修改
1 var queryC = from d in queryD
2 group d by d.PicId into g
3 select new ResultGroup()
4 {
5 PicId= g.Key,
6 Count = g.Count()
7 };
8
9
10 var query = from r in queryR
11 join c in queryC on r.FId equals c.PicId into g
12 from cg in g.DefaultIfEmpty()
13 join s in _repository.GetAll() on r.FId equals s.PicId into k
14 from sk in k.DefaultIfEmpty()
15 select new FilePictureRecordDto()
16 {
17 Type = r.Type,
18 Name = r.Name,
19 FId = r.FId,
20 IsDeleted = r.IsDeleted,
21 CreatiOnTime= r.CreationTime,
22 Id = r.Id,
23 Status = sk != null ? sk.Status : false,
24 IdentityType = cg != null ? (cg.Count > 1 ? IdentityTypeEnum.多 : IdentityTypeEnum.单) : IdentityTypeEnum.无
25 };
此处将分组后的count设为可空