public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
System.Data.Entity.Database.SetInitializer(new Mvc_CYou.Models.DataBase());
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
}
“System.Data.Entity.DropCreateDatabaseIfModelChanges`1”的类型初始值设定项引发异常。
谢谢!
可以参考http://blog.csdn.net/learn_2/article/details/7819781,你的实体模型可能不存在
我还是找不到哪一环节出问题了?
namespace Mvc_CYou.Models
{
public class DataBase : DropCreateDatabaseIfModelChanges<OMEntities>
{
protected override void Seed(OMEntities context)
{
var Users = new List<User>
{
new User{IdentityCardID="452724198101120001",LoginName="qjw900",Password="123456"}
};
Users.ForEach(a=>context.Users.Add(a));
}
}
}
namespace Mvc_CYou.Models
{
public class OMEntities:DbContext
{
/// <summary>
/// 用户表
/// </summary>
public DbSet<User> Users { get; set; }
}
}
namespace Mvc_CYou.Models
{
public class User
{
public string IdentityCardID { get; set; }
public string LoginName { get; set; }
public string Password { get; set; }
public DateTime? RegTime { get; set; }
}
}