模型
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);
}
結果就這樣了
這是什麼原因?怎麼解決?
在你的方法名後用尖括號加上你用的TContext的參數就可以了。