测试框架表示实体没有定义键内置实体 [英] Testing framework says entity has no key defined for built in entity

查看:248
本文介绍了测试框架表示实体没有定义键内置实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

推荐答案

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

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.

这篇关于测试框架表示实体没有定义键内置实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆