实体框架6.1.3使用模型构建器删除约定

时间:2015-12-28 19:56:45

标签: c# entity-framework

如何使用以下函数删除Entity Framework 6.1.3中的多个约定?

protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
       modelBuilder.Conventions.Remove(new PluralizingTableNameConvention());
    }

这是文档的链接,但此功能似乎不起作用?

https://msdn.microsoft.com/en-us/library/system.data.entity.modelconfiguration.configuration.conventionsconfiguration.remove%28v=vs.113%29.aspx#M:System.Data.Entity.ModelConfiguration.Configuration.ConventionsConfiguration.Remove%28System.Data.Entity.ModelConfiguration.Conventions.IConvention[]%29

我试过了:

def get_student():
    return input("Student Name(or blank to exit):")

def get_grades(name):
    def get_grade():
        while True:
            try: 
                return int(input("Enter Grade For %s(-1 to exit):"%name))
            except ValueError:
                 print("Error Expect An Int")
    return sum(list(iter(get_grade,-1)))

但这不起作用。

请发布一个如何使用它的示例。

由于

1 个答案:

答案 0 :(得分:2)

modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();