我正在尝试在linq中执行此查询:
select count(cd.Type) as count, cdt.Id, cdt.Name from DocumentTypes as cdt
join Documents as cd
on cdt.Id = cd.Type
group by cd.Type, cdt.Id, cdt.Name
order by count desc
到目前为止,我正在尝试这个:
var d = from cdt in context.DocumentTypes
join cd in context.Documents on cdt.Id equals cd.Type into c
from j in c.DefaultIfEmpty()
group j by j.Id into gj
orderby gj.Count()
from sg in gj.DefaultIfEmpty()
select new{ Id = sg.Id, Name = sg.Type};
但它不起作用。我收到以下错误消息:
转换为值类型'Int32'失败,因为具体化值为null。结果类型的泛型参数或查询必须使用可空类型。
我不明白这个错误。任何人都可以解释如何按照使用类型的频率获取id和类型吗?