Generate money type fields using code first EF CTP5

后端 未结 2 1380
野性不改
野性不改 2020-12-06 04:10

In this blog post: EF4 Code First Control Unicode and Decimal Precision, Scale with Attributes, Dane Morgridge used attributes to control the creation of di

2条回答
  •  孤街浪徒
    2020-12-06 04:56

    using System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive;
    
    public class MoneyAttribute : Attribute { }
    
    public class MoneyAttributeConvention : AttributeConfigurationConvention {
        public override void Apply(PropertyInfo memberInfo, DecimalPropertyConfiguration configuration, MoneyAttribute attribute) {
            configuration.ColumnType = "money";
        }
    }
    

    then you use like that

    [Money]
    public decimal Value { get; set; }
    

提交回复
热议问题