Add Column Name Convention to EF6 FluentAPI

ef-fluent-api entity-framework entity-framework-6

Accepted Answer

This has gotten incredibly easy using code-first, model-based practices. Simply create a class that implementsIStoreModelConvention ...

class PrefixConvention : IStoreModelConvention<EdmProperty>
{
    public void Apply(EdmProperty property, DbModel model)
    {
        property.Name = property.DeclaringType.Name + property.Name;
    }
}

... and incorporate it into the customs inOnModelCreating :

modelBuilder.Conventions.Add(new PrefixConvention());
3
11/18/2016 12:31:32 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow