简体   繁体   中英

EntityFramework7 - Conventions, Properties and Configurations

Trying to update to EntityFramework7, but having trouble finding these methods. In EF6, we could do things like this

Conventions

modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

Properties

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

Configurations

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

I have read 1 stackoverflow post, that says Configurations are no longer possible, so you have to write all this in the OnModalCreating method, which seems stupid, as the method will be massive, but maybe this was a older version?

I am using beta7

Keep in mind that beta7 is not yet feature complete, and that even RC1 will not have feature parity with EF6.

Custom conventions are on the backlog .

For properties you could something like the following;

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)");
            }
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM