尝试更新到EntityFramework7,但无法找到这些方法。在EF6中,我们可以这样做
约定
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
属性modelBuilder.Properties<DateTime>()
.Configure(c => c
.HasColumnType("datetime2")
.HasPrecision(0));
配置modelBuilder.Configurations.Add(new ModuleConfig());
我读过1 stackoverflow的帖子,说配置不再可能,所以你必须写所有这些在OnModalCreating方法,这似乎很愚蠢,作为方法将是巨大的,但也许这是一个旧版本?
我用beta7
请记住,beta7的功能尚未完成,即使是RC1也不会具有与EF6相同的功能。
自定义约定在待办事项列表中。
对于属性,可以像下面这样;
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)");
}
}
}
}