c# - IQueryable 上的 EF Core “InvalidOperationException:InvalidOperationException:Include 已用于非实体可查询”
问题描述
解决方案
If you change the query so that it no longer returns instances of the entity type that the query began with, then the include operators are ignored.
So your code is giving error. You can do like below where you can use Includes
in your first query and use OrderByDescending
ToListAsync
to next.
var postsQuery = _ctx.PostTag
.Include(st => st.Post)
.ThenInclude(s => s.AppUser)
.Include(st => st.Post)
.ThenInclude(s => s.PostTags)
.ThenInclude(st => st.Tag)
.Where(st => st.TagId == {provided TagId})
.Select(st => st.Post);
var postsWithExtraData = postsQuery
.OrderByDescending(s => s.TotalVoteCount)
.ToListAsync();
推荐阅读
- java - 当一个注入的依赖项需要同一类中的 bean 时,Spring 不会填充其他变量
- java - 无法从 com.google.android.exoplayer2.upstream.ResolvingDataSource 中找到符号“ResolvingDataSource”
- javascript - D3 散点图变换符号
- c# - 如何多次获取变量字符串和常量字符串之间的字符串
- azure-functions - 来自文件上传的 Terraform Azure 函数应用
- c++ - 使用 strlen 时,Valgrind 报告“使用大小为 4 的未初始化值”
- c# - 用导航属性替换连接
- time - 每 10 行增加时间 2 秒
- .net - .NET Core MVC 可以使用模型进行 Ajax 重定向页面
- python - 在 Flask-WTF 中填充表单并选择默认值