有关此问题的快速问题。
我有一个错误无法从数据库中获取数据, EF Core或我的linq查询有问题吗?EF核心组在导航属性
var query = _postRepository.Table
.Where(x => x.Approval == true)
.Include(p => p.Industry)
.GroupBy(grp => new { grp.Industry.Id, grp.Industry.Name })
.Select(s => new JobPostStatistics
{
IndustryId = s.Key.Id,
IndustryName = s.Key.Name,
TotalJobPost = s.Count()
});
return query.Take(6).ToList();
出现InvalidOperationException:序列包含多个元素
你确定这是你的错误吗?这个错误是由Single或SingleOrDefault造成的 –
很难推断问题出在哪里。查询似乎没问题。你可以请你的JobPostStatistics显示你的代码吗? –
查询当你尝试.list或.singleordefault它遇到错误invalidoperatinexception所以认为它是错误的核心? – tomato45un