- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我的 IQueryable 看起来像这样:
IQueryable<TEntity> query = context.Set<TEntity>();
query = query.Include("Car").ThenInclude("Model");
'IQueryable' does not contain a definition for 'ThenInclude' and no extension method 'ThenInclude' accepting a first argument of type 'IQueryable' could be found (are you missing a using directive or an assembly reference?)
我有所有需要的引用资料:
using Content.Data.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
为什么它不识别 ThenInclude?
查询:
[Content.Data.Models.Article]).Where(x => (((x.BaseContentItem.SiteId == value(Content.Business.Managers.ArticleManager+<>c__DisplayClass8_0).id) AndAlso x.BaseContentItem.IsActive) AndAlso x.BaseContentItem.IsLive)).Include("BaseContentItem").Include("BaseContentItem.TopicTag").Include("MainImage")}
包含 .Include("BaseContentItem.TopicTag")
后失败部分。
所以我刚刚读到,使用通用存储库你会失去 ThenInclude。我正在使用这个通用代表:
public class ReadOnlyRepository<TContext> : IReadOnlyRepository
where TContext : DbContext
{
protected readonly TContext context;
public ReadOnlyRepository(TContext context)
{
this.context = context;
}
private IQueryable<TEntity> GetQueryable<TEntity>(
Expression<Func<TEntity, bool>> filter = null,
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null,
string includeProperties = null,
int? skip = null,
int? take = null)
where TEntity : class, IEntity
{
includeProperties = includeProperties ?? string.Empty;
IQueryable<TEntity> query = context.Set<TEntity>();
if (filter != null)
{
query = query.Where(filter);
}
foreach (var includeProperty in includeProperties.Split
(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
{
query = query.Include(includeProperty);
}
if (orderBy != null)
{
query = orderBy(query);
}
if (skip.HasValue)
{
query = query.Skip(skip.Value);
}
if (take.HasValue)
{
query = query.Take(take.Value);
}
return query;
}
最佳答案
ThenInclude
仅在您使用带有 lambda 表达式参数的 Include
重载时可用:
query = query.Include(e => e.Car).ThenInclude(e => e.Model);
当您使用带字符串参数的 Include
重载时,不需要 ThenInclude
因为您可以在传递的字符串中指定整个属性路径:
query = query.Include("Car.Model");
关于c# - ThenInclude 在 EF Core 查询中无法识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46000602/
众所周知,EF-Core 中没有延迟加载。因此,这意味着我不得不事后才进行查询。既然要思考,那我就试着好好的去做吧。 我有一个相当标准的更新查询,但我想嘿,我不必总是包含 HeaderImage 和
我一直在尝试使用 Entity Framework,在遇到以下错误后,我尝试使用 ThenInclude 来解决它。 The expression '[x].ModelA.ModelB' passed
这是我的通用存储库: public class Repository : IRepository where T : BaseEntity { private DbContext _dbCon
我将.NET Framework(EF6)代码传输到ASP.NET Core(EF Core),但我偶然发现了这个问题。这是一些示例代码: 在EF6中,我使用Include()和Select()进行预
有没有人看到我做错了什么? ProjectActivityTasks 具有 UnitOfMeasureId 和 ProjectActivityTaskTypeId。按照它的编写方式,它认为 UnitO
我看到一些包含 ThenInclude 的 LINQ 代码示例。我在哪里可以找到这样的方法?在外部库或其他命名空间中。 我想用这样的方法获取派生数据,但是我找不到这样的方法或者你知道其他解决方案吗
这个问题在这里已经有了答案: Filtering on Include in EF Core (9 个回答) 关闭 5 个月前。 我有 3 个实体: Questionnaire.cs: public
我使用以下查询根据需要过滤我的 BranchId。 var query = await _dbContext.TargetItems .Include(i => i.Br
我有一个这样的查询 return await _ctx.Activities .Include(a => a.Attributes) .Include(
我的 IQueryable 看起来像这样: IQueryable query = context.Set(); query = query.Include("Car").ThenInclude("M
英孚核心 3.1 我见过Specification例如,并希望实现 ThenInclude 模式。 public static class QuerySpecificationExtensions {
我正在创建一个 ASP.NET Core API 应用程序,并依赖于 EF Core。我有这样定义的实体: public class AppUser : IdentityUser { publ
我将 Entity Framework Core 与 Repository Pattern 一起使用,但遇到一个问题。 我有类 Customer、Company 和 Email,其中隐藏了与此处无关的
假设首先有这些模型: Method 有一个 OriginalCodeOriginalCode 有很多 MutantMutant 有许多 ParseSubTree 现在,当查询 Method 时,我希望
这个问题在这里已经有了答案: Can not load related data with Include or ThenInclude or Select/Many with ONE query
我需要在 ThenInclude 中使用 where var templatesFields = await _context.Sections .Include(x
假设首先拥有这些模型: Method有一个 OriginalCodeOriginalCode有很多Mutant秒Mutant有很多ParseSubTree秒 现在在 Method 上查询时我想要另一个
以前(使用 .net 4.5.2 和 EF 6 时)。我有一个通用的 Get接受多个包含的方法如下; public abstract class DataContext : IdentityDbCon
好的,所以我有一个表 Building,其中包含该建筑物中的所有人员。然而,每个人都有一个职业,它本身就是一个实体,根据可用的内容添加到 Person 实体。 var data = _dbcontex
我正在使用 EF core 2.0 并想过滤子集合。谁能帮助我如何在 EF 核心 2.0 中执行此操作? var items = await _context.RiskType
我是一名优秀的程序员,十分优秀!