4 changed files with 411 additions and 61 deletions
-
68src/Shentun.Peis.EntityFrameworkCore/DbMapping/Asbitems/AsbitemDbMapping.cs
-
115src/Shentun.Peis.EntityFrameworkCore/EntityFrameworkCore/PeisDbContext.cs
-
2src/Shentun.Peis.EntityFrameworkCore/EntityFrameworkCore/PeisEntityFrameworkCoreModule.cs
-
287src/Shentun.Peis.EntityFrameworkCore/EntityFrameworkCore/PeisEntityTypeBuilder.cs
@ -0,0 +1,68 @@ |
|||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
using Microsoft.EntityFrameworkCore.Metadata.Builders; |
||||
|
using Shentun.Peis.Books; |
||||
|
using Shentun.Peis.Models; |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.EntityFrameworkCore.Modeling; |
||||
|
|
||||
|
namespace Shentun.Peis.EntityFrameworkCore |
||||
|
{ |
||||
|
internal class AsbitemDbMapping : IEntityTypeConfiguration<Asbitem> |
||||
|
{ |
||||
|
public void Configure(EntityTypeBuilder<Asbitem> entity) |
||||
|
{ |
||||
|
entity.HasComment("组合项目"); |
||||
|
entity.Property(t => t.DisplayName).HasComment("名称"); |
||||
|
entity.Property(t => t.ShortName).HasComment("简称"); |
||||
|
entity.Property(t => t.ForSexId).HasComment("适用性别,M-男,F-女,A-全部"); |
||||
|
entity.Property(t => t.ItemTypeId).HasComment("项目类别"); |
||||
|
entity.Property(t => t.Price).HasComment("价格"); |
||||
|
entity.Property(t => t.DeviceTypeId).HasComment("仪器类别"); |
||||
|
entity.Property(t => t.InvoiceItemTypeId).HasComment("发票类别"); |
||||
|
entity.Property(t => t.IsItemResultMerger).HasComment("项目结果合并"); |
||||
|
entity.Property(t => t.IsBeforeEat).HasComment("餐前项目"); |
||||
|
entity.Property(t => t.ClinicalMeaning).HasComment("临床意义"); |
||||
|
entity.Property(t => t.DefaultResult).HasComment("默认结果"); |
||||
|
entity.Property(t => t.QueueTime).HasComment("候诊时间"); |
||||
|
entity.Property(t => t.IsDiagnosisFunction).HasComment("启用诊断函数"); |
||||
|
entity.Property(t => t.DiagnosisFunction).HasComment("诊断函数"); |
||||
|
entity.Property(t => t.IsContinueProcess).HasComment("诊断函数处理完毕后继续处理"); |
||||
|
entity.Property(t => t.IsPictureRotate).HasComment("体检报告图片旋转90°"); |
||||
|
entity.Property(t => t.IsCheck).HasComment("是检查项目"); |
||||
|
entity.Property(t => t.IsActive).HasComment("是启用"); |
||||
|
|
||||
|
|
||||
|
entity.Property(e => e.Id) |
||||
|
.IsFixedLength() |
||||
|
.HasComment("编号").HasColumnName("id"); |
||||
|
|
||||
|
|
||||
|
|
||||
|
entity.Property(e => e.DeviceTypeId).IsFixedLength(); |
||||
|
|
||||
|
entity.Property(e => e.ForSexId).HasDefaultValueSql("'A'::bpchar"); |
||||
|
|
||||
|
entity.Property(e => e.InvoiceItemTypeId).IsFixedLength(); |
||||
|
|
||||
|
entity.Property(e => e.ItemTypeId).IsFixedLength(); |
||||
|
|
||||
|
entity.HasOne(d => d.InvoiceItemType) |
||||
|
.WithMany(p => p.Asbitems) |
||||
|
.HasForeignKey(d => d.InvoiceItemTypeId) |
||||
|
.OnDelete(DeleteBehavior.ClientSetNull) |
||||
|
.HasConstraintName("fk_asbitem_invoice_item_type"); |
||||
|
|
||||
|
entity.HasOne(d => d.ItemType) |
||||
|
.WithMany(p => p.Asbitems) |
||||
|
.HasForeignKey(d => d.ItemTypeId) |
||||
|
.OnDelete(DeleteBehavior.ClientSetNull) |
||||
|
.HasConstraintName("fk_asbitem_item_type"); |
||||
|
|
||||
|
entity.ConfigureByConvention(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,287 @@ |
|||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
using Microsoft.EntityFrameworkCore.Metadata.Builders; |
||||
|
using System; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Auditing; |
||||
|
using Volo.Abp.Data; |
||||
|
using Volo.Abp.Domain.Entities; |
||||
|
using Volo.Abp.EntityFrameworkCore.ValueComparers; |
||||
|
using Volo.Abp.EntityFrameworkCore.ValueConverters; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
|
using Volo.Abp.ObjectExtending; |
||||
|
|
||||
|
namespace Shentun.Peis.EntityFrameworkCore |
||||
|
{ |
||||
|
public static class PeisEntityTypeBuilder |
||||
|
{ |
||||
|
public static void ConfigureByConvention(this EntityTypeBuilder b) |
||||
|
{ |
||||
|
b.TryConfigureConcurrencyStamp(); |
||||
|
b.TryConfigureExtraProperties(); |
||||
|
b.TryConfigureObjectExtensions(); |
||||
|
b.TryConfigureMayHaveCreator(); |
||||
|
b.TryConfigureMustHaveCreator(); |
||||
|
b.TryConfigureSoftDelete(); |
||||
|
b.TryConfigureDeletionTime(); |
||||
|
b.TryConfigureDeletionAudited(); |
||||
|
b.TryConfigureCreationTime(); |
||||
|
b.TryConfigureLastModificationTime(); |
||||
|
b.TryConfigureModificationAudited(); |
||||
|
b.TryConfigureMultiTenant(); |
||||
|
b.TryConfigureId(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public static void ConfigureId<T>(this EntityTypeBuilder<T> b) where T : class |
||||
|
{ |
||||
|
b.As<EntityTypeBuilder>().TryConfigureId(); |
||||
|
} |
||||
|
|
||||
|
public static void TryConfigureId(this EntityTypeBuilder b) |
||||
|
{ |
||||
|
|
||||
|
var props = b.Metadata.ClrType.GetProperties(); |
||||
|
foreach (var prop in props) |
||||
|
{ |
||||
|
if (prop.Name == "Id") |
||||
|
{ |
||||
|
b.Property("Id").HasColumnName("id"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
public static void ConfigureConcurrencyStamp<T>(this EntityTypeBuilder<T> b) where T : class, IHasConcurrencyStamp |
||||
|
{ |
||||
|
b.As<EntityTypeBuilder>().TryConfigureConcurrencyStamp(); |
||||
|
} |
||||
|
|
||||
|
public static void TryConfigureConcurrencyStamp(this EntityTypeBuilder b) |
||||
|
{ |
||||
|
if (b.Metadata.ClrType.IsAssignableTo<IHasConcurrencyStamp>()) |
||||
|
{ |
||||
|
b.Property("ConcurrencyStamp").IsConcurrencyToken().HasMaxLength(40) |
||||
|
.HasColumnName("concurrency_stamp"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public static void ConfigureExtraProperties<T>(this EntityTypeBuilder<T> b) where T : class, IHasExtraProperties |
||||
|
{ |
||||
|
b.As<EntityTypeBuilder>().TryConfigureExtraProperties(); |
||||
|
} |
||||
|
|
||||
|
public static void TryConfigureExtraProperties(this EntityTypeBuilder b) |
||||
|
{ |
||||
|
if (b.Metadata.ClrType.IsAssignableTo<IHasExtraProperties>()) |
||||
|
{ |
||||
|
b.Property<ExtraPropertyDictionary>("ExtraProperties").HasColumnName("ExtraProperties").HasConversion(new ExtraPropertiesValueConverter(b.Metadata.ClrType)) |
||||
|
.Metadata.SetValueComparer(new ExtraPropertyDictionaryValueComparer()); |
||||
|
b.TryConfigureObjectExtensions(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public static void ConfigureObjectExtensions<T>(this EntityTypeBuilder<T> b) where T : class, IHasExtraProperties |
||||
|
{ |
||||
|
b.As<EntityTypeBuilder>().TryConfigureObjectExtensions(); |
||||
|
} |
||||
|
|
||||
|
public static void TryConfigureObjectExtensions(this EntityTypeBuilder b) |
||||
|
{ |
||||
|
if (b.Metadata.ClrType.IsAssignableTo<IHasExtraProperties>()) |
||||
|
{ |
||||
|
ObjectExtensionManager.Instance.ConfigureEfCoreEntity(b); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public static void ApplyObjectExtensionMappings(this EntityTypeBuilder b) |
||||
|
{ |
||||
|
ObjectExtensionManager.Instance.ConfigureEfCoreEntity(b); |
||||
|
} |
||||
|
|
||||
|
public static void ConfigureSoftDelete<T>(this EntityTypeBuilder<T> b) where T : class, ISoftDelete |
||||
|
{ |
||||
|
b.As<EntityTypeBuilder>().TryConfigureSoftDelete(); |
||||
|
} |
||||
|
|
||||
|
public static void TryConfigureSoftDelete(this EntityTypeBuilder b) |
||||
|
{ |
||||
|
if (b.Metadata.ClrType.IsAssignableTo<ISoftDelete>()) |
||||
|
{ |
||||
|
b.Property("IsDeleted").IsRequired().HasDefaultValue(false) |
||||
|
.HasColumnName("IsDeleted"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public static void ConfigureDeletionTime<T>(this EntityTypeBuilder<T> b) where T : class, IHasDeletionTime |
||||
|
{ |
||||
|
b.As<EntityTypeBuilder>().TryConfigureDeletionTime(); |
||||
|
} |
||||
|
|
||||
|
public static void TryConfigureDeletionTime(this EntityTypeBuilder b) |
||||
|
{ |
||||
|
if (b.Metadata.ClrType.IsAssignableTo<IHasDeletionTime>()) |
||||
|
{ |
||||
|
b.TryConfigureSoftDelete(); |
||||
|
b.Property("DeletionTime").IsRequired(required: false).HasColumnName("DeletionTime"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public static void ConfigureMayHaveCreator<T>(this EntityTypeBuilder<T> b) where T : class, IMayHaveCreator |
||||
|
{ |
||||
|
b.As<EntityTypeBuilder>().TryConfigureMayHaveCreator(); |
||||
|
} |
||||
|
|
||||
|
public static void TryConfigureMayHaveCreator(this EntityTypeBuilder b) |
||||
|
{ |
||||
|
if (b.Metadata.ClrType.IsAssignableTo<IMayHaveCreator>()) |
||||
|
{ |
||||
|
b.Property("CreatorId").IsRequired(required: false).HasColumnName("creator_id"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public static void ConfigureMustHaveCreator<T>(this EntityTypeBuilder<T> b) where T : class, IMustHaveCreator |
||||
|
{ |
||||
|
b.As<EntityTypeBuilder>().TryConfigureMustHaveCreator(); |
||||
|
} |
||||
|
|
||||
|
public static void TryConfigureMustHaveCreator(this EntityTypeBuilder b) |
||||
|
{ |
||||
|
if (b.Metadata.ClrType.IsAssignableTo<IMustHaveCreator>()) |
||||
|
{ |
||||
|
b.Property("CreatorId").IsRequired().HasColumnName("creator_id"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public static void ConfigureDeletionAudited<T>(this EntityTypeBuilder<T> b) where T : class, IDeletionAuditedObject |
||||
|
{ |
||||
|
b.As<EntityTypeBuilder>().TryConfigureDeletionAudited(); |
||||
|
} |
||||
|
|
||||
|
public static void TryConfigureDeletionAudited(this EntityTypeBuilder b) |
||||
|
{ |
||||
|
if (b.Metadata.ClrType.IsAssignableTo<IDeletionAuditedObject>()) |
||||
|
{ |
||||
|
b.TryConfigureDeletionTime(); |
||||
|
b.Property("DeleterId").IsRequired(required: false).HasColumnName("DeleterId"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public static void ConfigureCreationTime<T>(this EntityTypeBuilder<T> b) where T : class, IHasCreationTime |
||||
|
{ |
||||
|
b.As<EntityTypeBuilder>().TryConfigureCreationTime(); |
||||
|
} |
||||
|
|
||||
|
public static void TryConfigureCreationTime(this EntityTypeBuilder b) |
||||
|
{ |
||||
|
if (b.Metadata.ClrType.IsAssignableTo<IHasCreationTime>()) |
||||
|
{ |
||||
|
b.Property("CreationTime").IsRequired().HasColumnName("creation_time"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public static void ConfigureCreationAudited<T>(this EntityTypeBuilder<T> b) where T : class, ICreationAuditedObject |
||||
|
{ |
||||
|
b.As<EntityTypeBuilder>().TryConfigureCreationAudited(); |
||||
|
} |
||||
|
|
||||
|
public static void TryConfigureCreationAudited(this EntityTypeBuilder b) |
||||
|
{ |
||||
|
if (b.Metadata.ClrType.IsAssignableTo<ICreationAuditedObject>()) |
||||
|
{ |
||||
|
b.As<EntityTypeBuilder>().TryConfigureCreationTime(); |
||||
|
b.As<EntityTypeBuilder>().TryConfigureMayHaveCreator(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public static void ConfigureLastModificationTime<T>(this EntityTypeBuilder<T> b) where T : class, IHasModificationTime |
||||
|
{ |
||||
|
b.As<EntityTypeBuilder>().TryConfigureLastModificationTime(); |
||||
|
} |
||||
|
|
||||
|
public static void TryConfigureLastModificationTime(this EntityTypeBuilder b) |
||||
|
{ |
||||
|
if (b.Metadata.ClrType.IsAssignableTo<IHasModificationTime>()) |
||||
|
{ |
||||
|
b.Property("LastModificationTime").IsRequired(required: false).HasColumnName("last_modification_time"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public static void ConfigureModificationAudited<T>(this EntityTypeBuilder<T> b) where T : class, IModificationAuditedObject |
||||
|
{ |
||||
|
b.As<EntityTypeBuilder>().TryConfigureModificationAudited(); |
||||
|
} |
||||
|
|
||||
|
public static void TryConfigureModificationAudited(this EntityTypeBuilder b) |
||||
|
{ |
||||
|
if (b.Metadata.ClrType.IsAssignableTo<IModificationAuditedObject>()) |
||||
|
{ |
||||
|
b.TryConfigureLastModificationTime(); |
||||
|
b.Property("LastModifierId").IsRequired(required: false).HasColumnName("last_modifier_id"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public static void ConfigureAudited<T>(this EntityTypeBuilder<T> b) where T : class, IAuditedObject |
||||
|
{ |
||||
|
b.As<EntityTypeBuilder>().TryConfigureAudited(); |
||||
|
} |
||||
|
|
||||
|
public static void TryConfigureAudited(this EntityTypeBuilder b) |
||||
|
{ |
||||
|
if (b.Metadata.ClrType.IsAssignableTo<IAuditedObject>()) |
||||
|
{ |
||||
|
b.As<EntityTypeBuilder>().TryConfigureCreationAudited(); |
||||
|
b.As<EntityTypeBuilder>().TryConfigureModificationAudited(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public static void ConfigureFullAudited<T>(this EntityTypeBuilder<T> b) where T : class, IFullAuditedObject |
||||
|
{ |
||||
|
b.As<EntityTypeBuilder>().TryConfigureFullAudited(); |
||||
|
} |
||||
|
|
||||
|
public static void TryConfigureFullAudited(this EntityTypeBuilder b) |
||||
|
{ |
||||
|
if (b.Metadata.ClrType.IsAssignableTo<IFullAuditedObject>()) |
||||
|
{ |
||||
|
b.As<EntityTypeBuilder>().TryConfigureAudited(); |
||||
|
b.As<EntityTypeBuilder>().TryConfigureDeletionAudited(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public static void ConfigureMultiTenant<T>(this EntityTypeBuilder<T> b) where T : class, IMultiTenant |
||||
|
{ |
||||
|
b.As<EntityTypeBuilder>().TryConfigureMultiTenant(); |
||||
|
} |
||||
|
|
||||
|
public static void TryConfigureMultiTenant(this EntityTypeBuilder b) |
||||
|
{ |
||||
|
if (b.Metadata.ClrType.IsAssignableTo<IMultiTenant>()) |
||||
|
{ |
||||
|
b.Property("TenantId").IsRequired(required: false).HasColumnName("TenantId"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public static void ConfigureCreationAuditedAggregateRoot<T>(this EntityTypeBuilder<T> b) where T : class |
||||
|
{ |
||||
|
b.As<EntityTypeBuilder>().TryConfigureCreationAudited(); |
||||
|
b.As<EntityTypeBuilder>().TryConfigureExtraProperties(); |
||||
|
b.As<EntityTypeBuilder>().TryConfigureConcurrencyStamp(); |
||||
|
} |
||||
|
|
||||
|
public static void ConfigureAuditedAggregateRoot<T>(this EntityTypeBuilder<T> b) where T : class |
||||
|
{ |
||||
|
b.As<EntityTypeBuilder>().TryConfigureAudited(); |
||||
|
b.As<EntityTypeBuilder>().TryConfigureExtraProperties(); |
||||
|
b.As<EntityTypeBuilder>().TryConfigureConcurrencyStamp(); |
||||
|
} |
||||
|
|
||||
|
public static void ConfigureFullAuditedAggregateRoot<T>(this EntityTypeBuilder<T> b) where T : class |
||||
|
{ |
||||
|
b.As<EntityTypeBuilder>().TryConfigureFullAudited(); |
||||
|
b.As<EntityTypeBuilder>().TryConfigureExtraProperties(); |
||||
|
b.As<EntityTypeBuilder>().TryConfigureConcurrencyStamp(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue