Entity Framework complex type's columns naming convention

后端 未结 1 1086
故里飘歌
故里飘歌 2021-01-13 18:11

Using complex types the default column naming convention uses underscore. That means having type defined that way:

[ColmplexType]
public class Contact
{
            


        
相关标签:
1条回答
  • 2021-01-13 18:27

    I've never done this before but it's worth trying the ComplexTypeAttributeConvention, you can remove the default one and add the custom one to DbModelBuilder.Conventions:

    public class CustomComplexTypeAttributeConvention : ComplexTypeAttributeConvention {
        public CustomComplexTypeAttributeConvention(){
           Properties().Configure(p => p.HasColumnName(p.ClrPropertyInfo.Name));
        }
    }
    
    protected override void OnModelCreating(DbModelBuilder modelBuilder){
       modelBuilder.Conventions.Remove<ComplexTypeAttributeConvention>();
       modelBuilder.Conventions.Add(new CustomComplexTypeAttributeConvention());
       //...
    }
    
    0 讨论(0)
提交回复
热议问题