Add Column Name Convention to EF6 FluentAPI

后端 未结 1 993
栀梦
栀梦 2020-12-21 10:31

This question was asked here 4 years ago: EF Mapping to prefix all column names within a table I\'m hoping there\'s better handling these days.

I\'m using EF6 Fluen

相关标签:
1条回答
  • 2020-12-21 11:28

    With model-based code-first conventions this has become very simple. Just create a class that implements IStoreModelConvention ...

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

    ... and add it to the conventions in OnModelCreating:

    modelBuilder.Conventions.Add(new PrefixConvention());
    
    0 讨论(0)
提交回复
热议问题