模型
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);
}