DbMigrationsConfiguration(TContext).Seed 方法的问题

模型

 namespace MvcDemo.Models
{
    public class SysController:MvcDemoEntities
    {
        public string ControllerDisplayName { get; set; }
        public string Ico { get; set; }
    }
}

上下文

 namespace MvcDemo.Models
{
    public class MvcDemoEntities:DbContext
    {
        public DbSet<SysController> syscontroller { get; set; }
    }
}

这个是seed方法

 namespace MvcDemo.Models
{
    public class Configuration:DbMigrationsConfiguration<MvcDemoEntities>
    {
        protected override void Seed(MvcDemoEntities context) 
        {
            var sysControllers = new List<SysController>
        {
            new SysController 
            {
                ControllerDisplayName="abcd",
            },
            new SysController 
            {
                ControllerDisplayName="asdaf",
            },
            new SysController 
            {
                ControllerDisplayName="dfsgs",
            },
            new SysController 
            {
                ControllerDisplayName="dgsds",
            },
            new SysController 
            {
                ControllerDisplayName="fgsdfsd",
            },
            new SysController 
            {
                ControllerDisplayName="sdgdf",
            },

        };
        }

    }
}

然后在Global.asax中声明

 protected void Application_Start()
        {
            System.Data.Entity.Database.SetInitializer(new MvcDemo.Models.Configuration());
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }

结果就这样了
图片说明
这是什么原因?怎么解决?

查看全部
sinat_30056991
sinat_30056991
2015/07/30 09:42
  • ontext
  • asp.net
  • mvc
  • 数据库
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复