问题描述
- 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); }
解决方案
在你的方法名后用尖括号加上你用的TContext的参数就可以了。
解决方案二:
HibernateDao的countCriteriaResult方法有问题的
时间: 2024-10-23 18:19:49