2015-10-09 27 views
1

尝试更新到EntityFramework7,但无法找到这些方法。在EF6,我们可以做这样的事情EntityFramework7 - 约定,属性和配置

约定

modelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); 

属性

modelBuilder.Properties<DateTime>() 
      .Configure(c => c 
       .HasColumnType("datetime2") 
       .HasPrecision(0)); 

配置

modelBuilder.Configurations.Add(new ModuleConfig()); 

我已阅读1周计算器后,即表示配置不再可能的,所以你必须在OnModalCreating方法中编写所有这些,这似乎很愚蠢,因为这个方法会很大,但也许这是一个旧版本?

我使用β7的

回答

3

记住β7的是没有完整的功能,而且即使RC1不会有EF6功能奇偶校验。

自定义约定在backlog

对于属性,你可以像下面这样的东西;

protected override void OnModelCreating(ModelBuilder builder) 
{ 
    foreach (var type in builder.Model.EntityTypes.Where(type => type.HasClrType)) 
    { 
     foreach (var property in type.Properties) 
     { 
      if (property.ClrType == typeof(DateTime)) 
      { 
       builder.Entity(type.ClrType) 
        .Property(property.ClrType, property.Name) 
        .HasSqlServerColumnType("datetime2(0)"); 
      } 
     } 
    } 
} 
+0

.GetClrTypes不存在?而建筑师应该是模型建造者? – Gillardo

+0

呵呵,看起来像我做了一个方法,当我做了类似的事情。更新。 –

+0

完美!谢谢 – Gillardo