|
@@ -1,5 +1,7 @@
|
|
|
using Business.Models;
|
|
using Business.Models;
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
+using System.Linq;
|
|
|
|
|
+using System.Reflection;
|
|
|
using Volo.Abp.Data;
|
|
using Volo.Abp.Data;
|
|
|
using Volo.Abp.EntityFrameworkCore;
|
|
using Volo.Abp.EntityFrameworkCore;
|
|
|
|
|
|
|
@@ -21,6 +23,18 @@ namespace Business.EntityFrameworkCore
|
|
|
|
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
|
{
|
|
{
|
|
|
|
|
+ modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly());
|
|
|
|
|
+ foreach (var entityType in modelBuilder.Model.GetEntityTypes())
|
|
|
|
|
+ {
|
|
|
|
|
+ var type = entityType.ClrType;
|
|
|
|
|
+ var props = type.GetProperties().Where(c => c.IsDefined(typeof(DecimalPrecisionAttribute),true)).ToArray();
|
|
|
|
|
+ foreach (var p in props)
|
|
|
|
|
+ {
|
|
|
|
|
+ //ͨ¹ý×Ô¶¨ÒådecimalAttributeÉèÖÃdecimal¾«¶È
|
|
|
|
|
+ var precis = p.GetCustomAttribute<DecimalPrecisionAttribute>();
|
|
|
|
|
+ modelBuilder.Entity(type).Property(p.Name).HasColumnType($"decimal({precis.Precision},{precis.Scale})");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
base.OnModelCreating(modelBuilder);
|
|
base.OnModelCreating(modelBuilder);
|
|
|
modelBuilder.ConfigureBusiness();
|
|
modelBuilder.ConfigureBusiness();
|
|
|
}
|
|
}
|