Entity framework core EF7中的预测
我尝试在Entity Framework 7中执行以下简单投影,并得到错误:Entity framework core EF7中的预测,entity-framework-core,Entity Framework Core,我尝试在Entity Framework 7中执行以下简单投影,并得到错误: System.InvalidOperationException was unhandled by user code HResult=-2146233079 Message=When called from 'VisitMethodCallExpression', expressions of type 'Expression' can only be replaced with other non-nul
System.InvalidOperationException was unhandled by user code
HResult=-2146233079
Message=When called from 'VisitMethodCallExpression', expressions of type 'Expression' can only be replaced with other non-null expressions of type 'Expression'.
Source=Remotion.Linq
代码如下:
//try simple projection with linq syntax
var blogSummaries1 = blogContext.Blogs.Select(blog => new
{
Id = blog.Id,
Name = blog.Name,
PostCount = blog.Posts.Count()
}).ToList();
//That threw
//try simple projection with query syntax
var blogSummaries2 = (from blog in blogContext.Blogs
select new
{
Id = blog.Id,
Name = blog.Name,
PostCount = blog.Posts.Count()
}).ToList();
//That threw
同样的代码也适用于EF6
我可以在EF 7中执行此操作并加载所有数据:
var blogs = blogContext.Blogs.Include(b => b.Posts).ToList();
所以我不认为这是一个一般的配置问题
EF 7中还没有包含对投影的支持吗?您不想使用
Include(b=>b.Posts)
,因为这将使EF加载关系中的所有行,而不是执行SELECT COUNT(*)
。看起来像是一个错误。你能?