Add Column Name Convention to EF6 FluentAPI

后端 未结 1 1004
栀梦
栀梦 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
    {
        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)
提交回复
热议问题