| | |
| | | using Microsoft.EntityFrameworkCore.ChangeTracking; |
| | | using Microsoft.EntityFrameworkCore.Diagnostics; |
| | | using Microsoft.EntityFrameworkCore.Metadata.Builders; |
| | | using Microsoft.EntityFrameworkCore.Migrations; |
| | | using Microsoft.Extensions.Configuration; |
| | | using Newtonsoft.Json; |
| | | using System; |
| | |
| | | /// <param name="query"></param> |
| | | /// <param name="cancellationToken"></param> |
| | | /// <returns></returns> |
| | | public static async Task<List<SelectQueryResultOption<TValue, TData>>> GetSelect<TEntity, TValue, TData>( |
| | | public static async Task<List<SelectOption<TValue, TData>>> GetSelect<TEntity, TValue, TData>( |
| | | this SelectQuery<TValue, TData> request, |
| | | Func<TData, TValue> getValue, |
| | | Func<TData, string> getLabel, |
| | |
| | | var models = await q |
| | | .ProjectToType<TData>() |
| | | .ToListAsync(cancellationToken); |
| | | var options = new List<SelectQueryResultOption<TValue, TData>>(); |
| | | var options = new List<SelectOption<TValue, TData>>(); |
| | | foreach (var model in models) |
| | | { |
| | | var option = new SelectQueryResultOption<TValue, TData>(); |
| | | var option = new SelectOption<TValue, TData>(); |
| | | option.Data = model; |
| | | option.Value = getValue(model); |
| | | option.Label = getLabel(model); |
| | |
| | | /// <returns></returns> |
| | | public static async Task BuildEntity(ModelBuilder modelBuilder, Type dbContextLocator = null) |
| | | { |
| | | var xmlDoc = await XmlDocUtils.GetXmlDocAsync(); |
| | | foreach (var entityType in modelBuilder.Model.GetEntityTypes()) |
| | | if (App.GetService<IMigrator>() != null) |
| | | { |
| | | Console.WriteLine($"正在生成表:{entityType.Name}"); |
| | | // 获取实体类的XML注释,并设置为表注释 |
| | | var entityBuilder = modelBuilder.Entity(entityType.ClrType); |
| | | string typeComment = (await entityType.ClrType.GetXmlDocMemberAsync(xmlDoc))?.Summary; |
| | | if (!string.IsNullOrEmpty(typeComment)) |
| | | var xmlDoc = await XmlDocUtils.GetXmlDocAsync(); |
| | | foreach (var entityType in modelBuilder.Model.GetEntityTypes()) |
| | | { |
| | | Console.WriteLine($"正在生成表注释:{entityType.Name}-{typeComment}"); |
| | | entityBuilder.ToTable(it => it.HasComment(typeComment)); |
| | | } |
| | | // 获取实体属性的XML注释,并设置为列注释 |
| | | var properties = entityType.ClrType.GetProperties() |
| | | .Where(p => |
| | | p.CanRead |
| | | && p.CanWrite |
| | | && !typeof(System.Collections.ICollection).IsAssignableFrom(p.PropertyType) |
| | | && (p.PropertyType.IsClass ? p.PropertyType.FullName.Contains("System.") : true)); |
| | | foreach (var property in properties) |
| | | { |
| | | string propComment = (await property.GetXmlDocMemberAsync(xmlDoc))?.Summary; |
| | | if (!string.IsNullOrEmpty(propComment)) |
| | | Console.WriteLine($"正在生成表:{entityType.Name}"); |
| | | // 获取实体类的XML注释,并设置为表注释 |
| | | var entityBuilder = modelBuilder.Entity(entityType.ClrType); |
| | | string typeComment = (await entityType.ClrType.GetXmlDocMemberAsync(xmlDoc))?.Summary; |
| | | if (!string.IsNullOrEmpty(typeComment)) |
| | | { |
| | | Console.WriteLine($"正在生成属性注释:{property.Name}-{propComment}"); |
| | | entityBuilder.Property(property.Name).HasComment(propComment); |
| | | Console.WriteLine($"正在生成表注释:{entityType.Name}-{typeComment}"); |
| | | entityBuilder.ToTable(it => it.HasComment(typeComment)); |
| | | } |
| | | // 获取实体属性的XML注释,并设置为列注释 |
| | | var properties = entityType.ClrType.GetProperties() |
| | | .Where(p => |
| | | p.CanRead |
| | | && p.CanWrite |
| | | && !typeof(System.Collections.ICollection).IsAssignableFrom(p.PropertyType) |
| | | && (p.PropertyType.IsClass ? p.PropertyType.FullName.Contains("System.") : true)); |
| | | foreach (var property in properties) |
| | | { |
| | | string propComment = (await property.GetXmlDocMemberAsync(xmlDoc))?.Summary; |
| | | if (!string.IsNullOrEmpty(propComment)) |
| | | { |
| | | Console.WriteLine($"正在生成属性注释:{property.Name}-{propComment}"); |
| | | entityBuilder.Property(property.Name).HasComment(propComment); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | foreach (var entityType in modelBuilder.Model.GetEntityTypes()) |
| | | { |
| | | if (typeof(CommonEntity).IsAssignableFrom(entityType.ClrType)) |
| | | { |
| | | // 构建筛选条件:IsDeleted == false |
| | |
| | | modelBuilder.Entity(entityType.ClrType).HasQueryFilter(lambda); |
| | | } |
| | | } |
| | | |
| | | Console.WriteLine("数据库链接地址:" + App.Configuration.GetConnectionString("FlexJobApi")); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | |
| | | // 通过请求中获取当前操作人 |
| | | var logier = JwtUtils.GetCurrentLogier(); |
| | | var traceId = App.GetTraceId(); |
| | | |
| | | // 获取所有已更改的实体 |
| | | foreach (var entity in entities) |
| | |
| | | |
| | | // 赋值跟踪Id |
| | | prop = entity.Property(nameof(CommonEntity.TraceId)); |
| | | if (prop != null) |
| | | if (prop != null && prop.CurrentValue == null && traceId.IsNotNull()) |
| | | { |
| | | prop.CurrentValue = App.GetTraceId(); |
| | | prop.CurrentValue = traceId; |
| | | } |
| | | } |
| | | else |
| | |
| | | |
| | | // 赋值跟踪Id |
| | | prop = entity.Property(nameof(CommonEntity.TraceId)); |
| | | if (prop != null) |
| | | if (prop != null && traceId.IsNotNull()) |
| | | { |
| | | prop.CurrentValue = App.GetTraceId(); |
| | | prop.CurrentValue = traceId; |
| | | } |
| | | |
| | | // 软删除 |