• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

测试框架表示实体没有定义键内置实体

用户头像
it1352
帮助1

问题说明

Castle.Proxies.IdentityUserLogin: : EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType.  



我试图安装测试,它使用的EntityFramework 6.1版本,AspNet.Identity我MVC 5.1项目。核心版本2.0,AspNet.Identity.EntityFramework 2.0版本。我唯一的测试用例是很简单的,它是与IdentityUserLogin'和实体类型IdentityUserRole'上面的错误,一旦示数,因为我尝试运行。问题是,据我了解有两种这些实体的定义键!因为它们是由框架提供。我看不到明确其描述在我的代码的第一部分,但在数据库中,我可以看到他们都有钥匙。

I am trying to setup tests for my MVC 5.1 project which uses EntityFramework version 6.1, AspNet.Identity.Core version 2.0, AspNet.Identity.EntityFramework version 2.0. My only test case is very simple and it is erroring with the above error for 'IdentityUserLogin' and for Entity Type 'IdentityUserRole' as soon as I try to run. The problem is that as far as I understand there are keys defined for both of these entities! As they are provided by the framework. I can't see explicitly their description in my code first portion but in the database I can see they both have keys.

在我的测试项目中,我使用Microsoft.VisualStudio.TestTools.UnitTesting和MOQ(还有EF&放大器;标识核心库)。

In my test project I'm using Microsoft.VisualStudio.TestTools.UnitTesting and Moq (as well as the EF & Identity Core libs).

任何帮助或指向的资源将不胜感激。我无法找到具有类似错误的人。

Any help or just pointing to resources would be much appreciated. I couldn't find anyone having a similar error.

正确答案

#1

我有同样的问题,终于能够通过创建模拟得到的试运行,如下所示:

I had the same Problem and was finally able to get the test running by creating the mock as follows:

var mockContext = new Mock<MyDbContext>() { CallBase = true };



据我了解,素否则不调用基类实现。我猜 - - 而这些钥匙可能会在基类的实现来定义。OnModelCreating

As I understand it, the Mock otherwise does not call base class implementations. And those Keys will probably be defined in the base class implementation of - I guess - OnModelCreating.

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcfeibh
系列文章
更多 icon
同类精品
更多 icon
继续加载