修改正式发布文件
parent
659e92f95b
commit
7af0b6e6a5
|
@ -6,20 +6,32 @@
|
|||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
//"RootUrl": "http://123.56.181.144:8060/",
|
||||
"ConnectionStrings": {
|
||||
"RemoteNew": "Server=101.132.193.237,1433;Database=IRaCIS.Production;User ID=sa;Password=zhanying2021;TrustServerCertificate=true",
|
||||
"Hangfire": "Server=101.132.193.237,1433;Database=Hangfire.IRaCIS.Production;User ID=sa;Password=zhanying2021;TrustServerCertificate=true"
|
||||
//"RemoteNew": "Server=101.132.193.237,1433;Database=Prod_IRC;User ID=sa;Password=zhanying2021;TrustServerCertificate=true",
|
||||
//"Hangfire": "Server=101.132.193.237,1433;Database=Prod_IRC_Hangfire;User ID=sa;Password=zhanying2021;TrustServerCertificate=true"
|
||||
"RemoteNew": "Server=47.117.164.182,1432;Database=Prod_IRC;User ID=sa;Password=zhanying2021;TrustServerCertificate=true",
|
||||
"Hangfire": "Server=47.117.164.182,1432;Database=Prod_IRC_Hangfire;User ID=sa;Password=zhanying2021;TrustServerCertificate=true"
|
||||
},
|
||||
|
||||
"AliyunOSS": {
|
||||
"regionId": "cn-shanghai",
|
||||
"region": "oss-cn-shanghai",
|
||||
"endpoint": "https://oss-cn-shanghai.aliyuncs.com",
|
||||
"accessKeyId": "LTAI5tKvzs7ed3UfSpNk3xwQ",
|
||||
"accessKeySecret": "zTIceGEShlZDGnLrCFfIGFE7TXVRio",
|
||||
"bucketName": "zy-irc-store",
|
||||
"viewEndpoint": "https://zy-irc-cache.oss-cn-shanghai.aliyuncs.com"
|
||||
"ObjectStoreService": {
|
||||
"ObjectStoreUse": "AliyunOSS",
|
||||
"AliyunOSS": {
|
||||
"regionId": "cn-shanghai",
|
||||
"endpoint": "https://oss-cn-shanghai.aliyuncs.com",
|
||||
"accessKeyId": "LTAI5tKvzs7ed3UfSpNk3xwQ",
|
||||
"accessKeySecret": "zTIceGEShlZDGnLrCFfIGFE7TXVRio",
|
||||
"bucketName": "zy-irc-store",
|
||||
"roleArn": "acs:ram::1899121822495495:role/oss-upload",
|
||||
"viewEndpoint": "https://zy-irc-cache.oss-cn-shanghai.aliyuncs.com",
|
||||
"region": "oss-cn-shanghai"
|
||||
},
|
||||
"MinIO": {
|
||||
"endpoint": "http://192.168.3.68",
|
||||
"port": "8001",
|
||||
"useSSL": false,
|
||||
"accessKey": "IDFkwEpWej0b4DtiuThL",
|
||||
"secretKey": "Lhuu83yMhVwu7c1SnjvGY6lq74jzpYqifK6Qtj4h",
|
||||
"bucketName": "test"
|
||||
}
|
||||
},
|
||||
"BasicSystemConfig": {
|
||||
|
||||
|
|
|
@ -146,9 +146,7 @@ namespace IRaCIS.Application.Services
|
|||
{
|
||||
|
||||
|
||||
await _dicRepository._dbContext.Subject.Where(t => t.Id == Guid.Empty).ExecuteUpdateAsync(t => t
|
||||
.SetProperty(c => EF.Property<DateTime>(c, "UpdateTime"), u => DateTime.Now)
|
||||
.SetProperty(c => c.FirstName, u => "NewUserName"));
|
||||
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" });
|
||||
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Query;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IRaCIS.Core.Infra.EFCore
|
||||
{
|
||||
|
||||
public static class DynamicRelationalExtensions
|
||||
{
|
||||
static MethodInfo UpdateMethodInfo =
|
||||
typeof(RelationalQueryableExtensions).GetMethod(nameof(RelationalQueryableExtensions.ExecuteUpdate));
|
||||
|
||||
static MethodInfo UpdateAsyncMethodInfo =
|
||||
typeof(RelationalQueryableExtensions).GetMethod(nameof(RelationalQueryableExtensions.ExecuteUpdateAsync));
|
||||
|
||||
public static int ExecuteUpdate(this IQueryable query, string fieldName, object? fieldValue)
|
||||
{
|
||||
var updateBody = BuildUpdateBody(query.ElementType,
|
||||
new Dictionary<string, object?> { { fieldName, fieldValue } });
|
||||
|
||||
return (int)UpdateMethodInfo.MakeGenericMethod(query.ElementType).Invoke(null, new object?[] { query, updateBody });
|
||||
}
|
||||
|
||||
|
||||
public static int ExecuteUpdate(this IQueryable query, IReadOnlyDictionary<string, object?> fieldValues)
|
||||
{
|
||||
var updateBody = BuildUpdateBody(query.ElementType, fieldValues);
|
||||
|
||||
return (int)UpdateMethodInfo.MakeGenericMethod(query.ElementType).Invoke(null, new object?[] { query, updateBody });
|
||||
}
|
||||
|
||||
|
||||
static LambdaExpression BuildUpdateBody(Type entityType, IReadOnlyDictionary<string, object?> fieldValues)
|
||||
{
|
||||
var setParam = Expression.Parameter(typeof(SetPropertyCalls<>).MakeGenericType(entityType), "s");
|
||||
var objParam = Expression.Parameter(entityType, "e");
|
||||
|
||||
Expression setBody = setParam;
|
||||
|
||||
foreach (var pair in fieldValues)
|
||||
{
|
||||
var propExpression = Expression.PropertyOrField(objParam, pair.Key);
|
||||
var valueExpression = ValueForType(propExpression.Type, pair.Value);
|
||||
|
||||
// s.SetProperty(e => e.SomeField, value)
|
||||
setBody = Expression.Call(setBody, nameof(SetPropertyCalls<object>.SetProperty),
|
||||
new[] { propExpression.Type }, Expression.Lambda(propExpression, objParam), valueExpression);
|
||||
|
||||
}
|
||||
|
||||
// s => s.SetProperty(e => e.SomeField, value)
|
||||
var updateBody = Expression.Lambda(setBody, setParam);
|
||||
|
||||
return updateBody;
|
||||
}
|
||||
|
||||
static Expression ValueForType(Type desiredType, object? value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return Expression.Default(desiredType);
|
||||
}
|
||||
|
||||
if (value.GetType() != desiredType)
|
||||
{
|
||||
return Expression.Convert(Expression.Constant(value), desiredType);
|
||||
}
|
||||
|
||||
return Expression.Constant(value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue