@@ -21,6 +21,11 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace IRaCIS.Core.Infra.EFCore.Common
|
||||
{
|
||||
public interface IAuditingData
|
||||
{
|
||||
|
||||
Task InsertAddEntitys(List<EntityEntry> entitys);
|
||||
}
|
||||
public static class AuditOpt
|
||||
{
|
||||
public static readonly string Add = "Add";
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IRaCIS.Core.Infra.EFCore.Common
|
||||
{
|
||||
public interface IAuditingData
|
||||
{
|
||||
//Task IncomingEntitys(List<EntityEntry> entitys);
|
||||
|
||||
Task InsertAddEntitys(List<EntityEntry> entitys);
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,9 @@ using EntityFramework.Exceptions.Common;
|
||||
using System.Data;
|
||||
using IRaCIS.Core.Infrastructure;
|
||||
using System.Reflection.Metadata;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using Microsoft.VisualBasic;
|
||||
|
||||
namespace IRaCIS.Core.Infra.EFCore
|
||||
{
|
||||
@@ -75,7 +78,8 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||
builder.HasNoKey();
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
//遍历实体模型手动配置
|
||||
var typesToRegister = Assembly.GetExecutingAssembly().GetTypes().Where(q => q.GetInterface(typeof(IEntityTypeConfiguration<>).FullName) != null);
|
||||
foreach (var type in typesToRegister)
|
||||
@@ -86,7 +90,6 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
|
||||
foreach (var entityType in modelBuilder.Model.GetEntityTypes())
|
||||
{
|
||||
// 软删除配置
|
||||
@@ -100,8 +103,6 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||
{
|
||||
modelBuilder.Entity(entityType.ClrType).Property<Guid>(nameof(Entity.Id)).HasValueGenerator<MySequentialGuidValueGenerator>();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -116,11 +117,71 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||
{
|
||||
return Set<TableList>().FromSqlRaw($"EXEC dbo.procGetTableColumn {tableName}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 直接获取代码定义的模型,以及表上定义的Description 获取表信息 以及备注
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<TableList> GetContextTablesList()
|
||||
{
|
||||
var tableList = new List<TableList>();
|
||||
|
||||
foreach (var entityType in this.Model.GetEntityTypes())
|
||||
{
|
||||
var clrType = entityType.ClrType;
|
||||
var tableName = entityType.GetTableName();
|
||||
|
||||
var tableDescription = clrType.GetCustomAttribute<DescriptionAttribute>()?.Description ?? string.Empty;
|
||||
|
||||
tableList.Add(new TableList
|
||||
{
|
||||
Name = tableName,
|
||||
Remake = tableDescription,
|
||||
});
|
||||
}
|
||||
|
||||
return tableList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 直接获取代码定义的某个表的属性,以及属性上定义的Description 获取备注
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<TableList> GetContextTableColumnList(string tableName)
|
||||
{
|
||||
var tableColumList = new List<TableList>();
|
||||
|
||||
var entityType = this.Model.GetEntityTypes().FirstOrDefault(t => t.GetTableName().ToLower() == tableName.ToLower());
|
||||
|
||||
if (entityType == null)
|
||||
{
|
||||
throw new ArgumentException($"Table '{tableName}' not found.");
|
||||
}
|
||||
|
||||
var clrType = entityType.ClrType;
|
||||
|
||||
foreach (var property in entityType.GetProperties())
|
||||
{
|
||||
var columnName = property.GetColumnName();
|
||||
var columnDescription = clrType.GetProperty(property.Name)?.GetCustomAttribute<DescriptionAttribute>()?.Description ?? string.Empty;
|
||||
|
||||
tableColumList.Add(new TableList
|
||||
{
|
||||
Name = tableName,
|
||||
Remake = columnDescription,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
return tableColumList;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
public override async Task<int> SaveChangesAsync(CancellationToken cancellationToken = new CancellationToken())
|
||||
{
|
||||
|
||||
// 采用触发器的方式 设置 CreateUserId CreateTime UpdateTime UpdateUserId 稽查实体里面没有这四个字段的值 因为先后顺序的原因
|
||||
await AddAudit();
|
||||
|
||||
@@ -271,7 +332,6 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||
|
||||
public virtual DbSet<ReadingQuestionTrial> ReadingQuestionTrial { get; set; }
|
||||
|
||||
//public virtual DbSet<ReadingClinicalDataView> ReadingClinicalDataView { get; set; }
|
||||
|
||||
public virtual DbSet<ReadingClinicalDataPDF> ReadingClinicalDataPDF { get; set; }
|
||||
public virtual DbSet<ReadingConsistentClinicalData> ReadingConsistentClinicalData { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user