相关疑难解决方法(0)

实体框架核心不包含"包含"的定义

我正在尝试使用Entity Framework Core 1.0并尝试在通过dbcontext填充对象时使用.Include.

        EFTestContext context = new EFTestContext();
        var testEntity = context.TestEntity
            .Include(t => t.TestEntity2)
            .ToList();
Run Code Online (Sandbox Code Playgroud)

它给了我错误

不包含'Include'的定义,也没有扩展方法'Include'接受'DbSet'类型的第一个参数可以找到

到目前为止我在Stackoverflow中找到的唯一类似的东西是

IQueryable <T>不包含"包含"的定义,也没有包含"包含"的扩展方法

但是添加using语句

using System.Data.Entity;
Run Code Online (Sandbox Code Playgroud)

只要给我错误

名称空间'System.Data'中不存在类型或命名空间名称'Entity'(您是否缺少程序集引用?)

任何人都知道我需要获得包含在WF Core 1.0中显示的内容吗?

c#

27
推荐指数
1
解决办法
2万
查看次数

然后在EF Core查询中无法识别

我的IQueryable看起来像这样:

 IQueryable<TEntity> query = context.Set<TEntity>();
query = query.Include("Car").ThenInclude("Model");
Run Code Online (Sandbox Code Playgroud)

'IQueryable'不包含'ThenInclude'的定义,也没有扩展方法'ThenInclude'可以找到'IQueryable'类型的第一个参数(你是否缺少using指令或汇编引用?)

我需要所有参考资料:

using Content.Data.Models;    
using Microsoft.EntityFrameworkCore;    
using System;    
using System.Collections.Generic;    
using System.Linq;    
using System.Linq.Expressions;    
using System.Threading.Tasks;   
Run Code Online (Sandbox Code Playgroud)

为什么它不识别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")}
Run Code Online (Sandbox Code Playgroud)

包含.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 …
Run Code Online (Sandbox Code Playgroud)

c# linq entity-framework entity-framework-core

6
推荐指数
2
解决办法
4441
查看次数