EF OnModelCreating

Posted 封存的记忆

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了EF OnModelCreating相关的知识,希望对你有一定的参考价值。

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<IncludeMetadataConvention>();     //不创建EdmMetadata表
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();//移除复数表名的契约
            modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();//禁用一对多级联删除
            //表前缀
            modelBuilder.Types().Configure(entity => entity.ToTable(AppConstant.Tableprefix + entity.ClrType.Name));
            // 忽略列映射 Fluent API:NotMapped
            modelBuilder.Entity<ScheduledEvents>().Ignore(p => p.ScheduleType);
 
        }

以上是关于EF OnModelCreating的主要内容,如果未能解决你的问题,请参考以下文章