域名修改配置网址
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
c4f3b0d653
commit
7caabad651
|
@ -50,7 +50,7 @@
|
||||||
"FromEmail": "uat@extimaging.com",
|
"FromEmail": "uat@extimaging.com",
|
||||||
"FromName": "UAT_IRC",
|
"FromName": "UAT_IRC",
|
||||||
"AuthorizationCode": "SHzyyl2021",
|
"AuthorizationCode": "SHzyyl2021",
|
||||||
"SiteUrl": "http://uat.extimaging.com/login"
|
"SiteUrl": "http://irc.event.extimaging.com/login"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@
|
||||||
"FromName": "Test_IRC",
|
"FromName": "Test_IRC",
|
||||||
"AuthorizationCode": "SHzyyl2021",
|
"AuthorizationCode": "SHzyyl2021",
|
||||||
|
|
||||||
"SiteUrl": "http://test.extimaging.com/login"
|
"SiteUrl": "http://irc.test.extimaging.com/login"
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@
|
||||||
"FromEmail": "uat@extimaging.com",
|
"FromEmail": "uat@extimaging.com",
|
||||||
"FromName": "UAT_IRC",
|
"FromName": "UAT_IRC",
|
||||||
"AuthorizationCode": "SHzyyl2021",
|
"AuthorizationCode": "SHzyyl2021",
|
||||||
"SiteUrl": "http://uat.extimaging.com/login"
|
"SiteUrl": "http://irc.uat.extimaging.com/login"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -146,9 +146,11 @@ namespace IRaCIS.Application.Services
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
var aa= _dicRepository._dbContext.Subject.Where(t => t.Id == Guid.Empty).ExecuteUpdate("FirstName","ddd");
|
//var aa= _dicRepository._dbContext.Subject.Where(t => t.Id == Guid.Empty).ExecuteUpdate("FirstName","ddd");
|
||||||
|
|
||||||
await _repository.BatchUpdateAsync<Subject>(t => t.Id == Guid.Empty, u => new Subject() { FirstName = "fddd", LastName = "sss" });
|
await _repository.BatchUpdateAsync<Subject>(t => t.Id == Guid.Empty, u => new Subject() { FirstName = "fddd", LastName = "sss", UpdateTime = DateTime.Now });
|
||||||
|
|
||||||
|
await _repository.Where<Subject>().ExecuteUpdateAsync(t => t.SetProperty(t => t.UpdateTime, u => DateTime.Now));
|
||||||
|
|
||||||
return ResponseOutput.Ok();
|
return ResponseOutput.Ok();
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,8 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||||
static MethodInfo UpdateAsyncMethodInfo =
|
static MethodInfo UpdateAsyncMethodInfo =
|
||||||
typeof(RelationalQueryableExtensions).GetMethod(nameof(RelationalQueryableExtensions.ExecuteUpdateAsync));
|
typeof(RelationalQueryableExtensions).GetMethod(nameof(RelationalQueryableExtensions.ExecuteUpdateAsync));
|
||||||
|
|
||||||
|
#region 避免使用
|
||||||
|
|
||||||
public static int ExecuteUpdate(this IQueryable query, string fieldName, object? fieldValue)
|
public static int ExecuteUpdate(this IQueryable query, string fieldName, object? fieldValue)
|
||||||
{
|
{
|
||||||
var updateBody = BuildUpdateBody(query.ElementType,
|
var updateBody = BuildUpdateBody(query.ElementType,
|
||||||
|
@ -28,13 +30,51 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||||
return (int)UpdateMethodInfo.MakeGenericMethod(query.ElementType).Invoke(null, new object?[] { query, updateBody });
|
return (int)UpdateMethodInfo.MakeGenericMethod(query.ElementType).Invoke(null, new object?[] { query, updateBody });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static int ExecuteUpdate(this IQueryable query, IReadOnlyDictionary<string, object?> fieldValues)
|
public static int ExecuteUpdate(this IQueryable query, IReadOnlyDictionary<string, object?> fieldValues)
|
||||||
{
|
{
|
||||||
var updateBody = BuildUpdateBody(query.ElementType, fieldValues);
|
var updateBody = BuildUpdateBody(query.ElementType, fieldValues);
|
||||||
|
|
||||||
return (int)UpdateMethodInfo.MakeGenericMethod(query.ElementType).Invoke(null, new object?[] { query, updateBody });
|
return (int)UpdateMethodInfo.MakeGenericMethod(query.ElementType).Invoke(null, new object?[] { query, updateBody });
|
||||||
}
|
}
|
||||||
|
public static Task<int> ExecuteUpdateAsync(this IQueryable query, string fieldName, object? fieldValue, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var updateBody = BuildUpdateBody(query.ElementType,
|
||||||
|
new Dictionary<string, object?> { { fieldName, fieldValue } });
|
||||||
|
|
||||||
|
return (Task<int>)UpdateAsyncMethodInfo.MakeGenericMethod(query.ElementType).Invoke(null, new object?[] { query, updateBody, cancellationToken })!;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
public static Dictionary<string, object?> ExtractFieldValues<TSource>(this Expression<Func<TSource, TSource>> updateFactory)
|
||||||
|
{
|
||||||
|
var dic = new Dictionary<string, object?>();
|
||||||
|
var obj = (TSource)Activator.CreateInstance(typeof(TSource));
|
||||||
|
|
||||||
|
Func<TSource, TSource> func = updateFactory.Compile();
|
||||||
|
|
||||||
|
TSource applyObj = func(obj);
|
||||||
|
|
||||||
|
var propList = ((MemberInitExpression)updateFactory.Body).Bindings.Select(mb => mb.Member.Name)
|
||||||
|
.Select(propName => typeof(TSource).GetProperty(propName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)).ToList();
|
||||||
|
|
||||||
|
|
||||||
|
foreach (PropertyInfo prop in propList)
|
||||||
|
{
|
||||||
|
object value = prop.GetValue(applyObj);
|
||||||
|
dic.Add(prop.Name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return dic;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static Task<int> ExecuteUpdateAsync(this IQueryable query, IReadOnlyDictionary<string, object?> fieldValues, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var updateBody = BuildUpdateBody(query.ElementType, fieldValues);
|
||||||
|
|
||||||
|
return (Task<int>)UpdateAsyncMethodInfo.MakeGenericMethod(query.ElementType).Invoke(null, new object?[] { query, updateBody, cancellationToken })!;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static LambdaExpression BuildUpdateBody(Type entityType, IReadOnlyDictionary<string, object?> fieldValues)
|
static LambdaExpression BuildUpdateBody(Type entityType, IReadOnlyDictionary<string, object?> fieldValues)
|
||||||
|
|
|
@ -5,6 +5,7 @@ using IRaCIS.Core.Infrastructure;
|
||||||
using IRaCIS.Core.Infrastructure.Extention;
|
using IRaCIS.Core.Infrastructure.Extention;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Query;
|
using Microsoft.EntityFrameworkCore.Query;
|
||||||
|
using SharpCompress.Factories;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
@ -170,7 +171,7 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||||
if (where == null) throw new ArgumentNullException(nameof(where));
|
if (where == null) throw new ArgumentNullException(nameof(where));
|
||||||
|
|
||||||
|
|
||||||
#region batch delete bug
|
#region history 使用扩展删除包,同时自动赋值更新人 更新时间
|
||||||
|
|
||||||
var bindings = ((MemberInitExpression)updateFactory.Body).Bindings.ToList();
|
var bindings = ((MemberInitExpression)updateFactory.Body).Bindings.ToList();
|
||||||
|
|
||||||
|
@ -205,55 +206,29 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region efcore 7
|
#region efcore 7 & 8
|
||||||
|
|
||||||
//Dictionary<string, object> propValues = new Dictionary<string, object>();
|
|
||||||
|
|
||||||
//// 获取表达式体的 MemberInitExpression
|
|
||||||
//var memberInitExpr = (MemberInitExpression)updateFactory.Body;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//// 获取初始化的绑定信息
|
|
||||||
//var bindings = memberInitExpr.Bindings.ToList();
|
|
||||||
|
|
||||||
//var hasPropNameList = bindings.Select(t => t.Member.Name).ToList();
|
|
||||||
|
|
||||||
|
|
||||||
//// 遍历绑定信息
|
|
||||||
//foreach (MemberAssignment binding in bindings)
|
|
||||||
//{
|
//{
|
||||||
// // 获取属性名
|
// var fieldValues = updateFactory.ExtractFieldValues();
|
||||||
// string propName = binding.Member.Name;
|
|
||||||
|
|
||||||
// // 获取属性值,需要对表达式进行编译和调用
|
// var hasPropNameList = ((MemberInitExpression)updateFactory.Body).Bindings.Select(t => t.Member.Name).ToList();
|
||||||
// var propValue = Expression.Lambda(binding.Expression).Compile().DynamicInvoke();
|
|
||||||
|
|
||||||
// // 现在,你可以访问属性名和属性值
|
|
||||||
// propValues.Add(propName, propValue);
|
|
||||||
//}
|
|
||||||
|
|
||||||
// if (typeof(IAuditUpdate).IsAssignableFrom(typeof(T)))
|
// if (typeof(IAuditUpdate).IsAssignableFrom(typeof(T)))
|
||||||
// {
|
// {
|
||||||
|
|
||||||
// if (!hasPropNameList.Contains(nameof(IAuditUpdate.UpdateTime)))
|
// if (!hasPropNameList.Contains(nameof(IAuditUpdate.UpdateTime)))
|
||||||
// {
|
// {
|
||||||
// propValues.Add(nameof(IAuditUpdate.UpdateTime), DateTime.Now);
|
// fieldValues.Add(nameof(IAuditUpdate.UpdateTime), DateTime.Now);
|
||||||
|
|
||||||
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// if (!hasPropNameList.Contains(nameof(IAuditUpdate.UpdateUserId)))
|
// if (!hasPropNameList.Contains(nameof(IAuditUpdate.UpdateUserId)))
|
||||||
// {
|
// {
|
||||||
// propValues.Add(nameof(IAuditUpdate.UpdateUserId), updateUserId);
|
// fieldValues.Add(nameof(IAuditUpdate.UpdateUserId), updateUserId);
|
||||||
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
// return await _dbContext.Set<T>().IgnoreQueryFilters().Where(where).ExecuteUpdateAsync(fieldValues).ConfigureAwait(false) > 0;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
//return await _dbContext.Set<T>().IgnoreQueryFilters().Where(where).ExecuteUpdateAsync(s => s.SetProperty(t => "UpdateTime", u => "").se).ConfigureAwait(false) > 0;
|
|
||||||
|
|
||||||
////return await _dbContext.Set<T>().IgnoreQueryFilters().Where(where).ExecuteUpdateAsync(propValues.SetProperties<T>()).ConfigureAwait(false) > 0;
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue