[英]'Update-Database' in EF 4.3 code-first - Value cannot be null
Using asp.NET MVC3, I am creating trying to create an abstract class/model with the following: 使用asp.NET MVC3,我正在尝试使用以下内容创建一个抽象类/模型:
namespace core.Models.Concrete
{
public class item
{
[Key]
public Guid id { get; set; }
public Type ConcreteType { get; set; }
public itemtype Type { get; set; }
public string barcode { get; set; }
public int rating { get; set; }
public string Title { get; set; }
}
}
public enum itemtype
{
Game,
Book,
Film
}
Which is used by: 使用者:
namespace core.Models.Abstract
{
public class game : item
{
public gamePlatform platform { get; set; }
}
public enum gamePlatform
{
PC,
X360,
PS3,
Wii
}
}
When I run the update-database
in Entity Framework 4.3 code first migrations I get: 当我在Entity Framework 4.3代码中运行
update-database
,我得到的第一次迁移:
Value cannot be null.
Parameter name: key
Am I doing something wrong? 难道我做错了什么? Is this even an accepted way of doing things.I don't really want to use an interface as this would mean implementing all the fields in each thing that uses
item
这甚至是一种可接受的做事方式。我真的不想使用界面,因为这意味着实现每个使用
item
东西的所有字段
EDIT I have just found that this comes from the following code in global.asax.cs
in Application_Start: 编辑我刚刚发现这来自Application_Start中
global.asax.cs
中的以下代码:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
//System.Data.Entity.Database.SetInitializer<DataContext>(new DataContextInitializer());
using (coreContext TestContext = new coreContext())
{
var x =TestContext.Users.Count(); <!-- THIS LINE HERE
try
{
Roles.CreateRole("User");
}catch
{
//Already created
}
}
}
Core COntext: 核心COntext:
public class coreContext : DbContext
{
public DbSet<core.Models.Abstract.game> games { get; set; }
}
Your error is coming from public Type ConcreteType
, are you missing a class definition? 您的错误来自
public Type ConcreteType
,您是否缺少类定义? Type normally refers to System.Type is that what you're actually wanting to put in your class? 类型通常是指System.Type是你实际想要放在你班级的那个? EF has no way to translate that into a SQL type.
EF无法将其转换为SQL类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.