随笔分类 - EntityFramework
摘要:一、确保解决方案可以生成成功二、打开程序包管理器控制台三、默认项目选择DataContext所在项目四、运行命令Enable-Migrations,会在项目自动创建迁移配置,修改配置 AutomaticMigrationsEnabled = true; AutomaticMigrationDataLossAllowed = true;五、运行命令Update-Database,执行迁移。六、结束
阅读全文
摘要:这个问题也很恶心活生生的把我设计好的表名,在自动生成的时候加上了复数,整个库一眼看上去难看的要死只要重写OnModelCreating时中加上这句就OK了 protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); }
阅读全文
摘要:Global.Application_Start()调用DB结构初始化 Database.SetInitializer<YourContex>(new YourInitializer()); public class YourInitializer : DropCreateDatabaseIfModelChanges<YourContex> { protected override void Seed(YourContex context) { // This method will be called after migrat...
阅读全文
摘要:不用说也知道,第一次搞这个让我恶心了很久 <add name="【Contex同名】" connectionString="Data Source=【ServerIP】; Database=【DatabaseName】; User ID=; Password=;" providerName="System.Data.SqlClient"/>
阅读全文
浙公网安备 33010602011771号