【问题标题】:Entity Framework Core does not contain a definition for 'Include'Entity Framework Core 不包含“包含”的定义
【发布时间】:2016-08-23 17:18:18
【问题描述】:

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

        EFTestContext context = new EFTestContext();
        var testEntity = context.TestEntity
            .Include(t => t.TestEntity2)
            .ToList();

它给了我错误

不包含“包含”的定义,并且找不到接受“DbSet”类型的第一个参数的扩展方法“包含”

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

IQueryable<T> does not contain a definition for 'Include' and no extension method 'Include'

但是添加 using 语句

using System.Data.Entity;

把错误告诉我

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

有人知道我需要什么才能让包含显示在 WF Core 1.0 中吗?

【问题讨论】:

  • 愚蠢的问题,但你的代码中有using Microsoft.EntityFrameworkCore;。你提到了using System.Data.Entity;

标签: c#


【解决方案1】:

根据github 上的这个例子,这里是使用的:

using Microsoft.EntityFrameworkCore;
using System.Linq;

【讨论】:

  • 使用 Microsoft.EntityFrameworkCore;这就是我所缺少的......非常感谢!
  • github链接失效
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-07-15
  • 2016-08-04
  • 2017-03-24
  • 1970-01-01
  • 2020-08-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多