mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2026-01-21 18:48:27 +08:00
Synchronization code
This commit is contained in:
@@ -275,6 +275,7 @@ namespace SqlSugar
|
||||
private static List<NavMappingColumn> GetMappingColumn(Expression expression)
|
||||
{
|
||||
var body = ExpressionTool.GetLambdaExpressionBody(expression);
|
||||
var parameterName=(expression as LambdaExpression).Parameters.FirstOrDefault().Name;
|
||||
List<NavMappingColumn> result = new List<NavMappingColumn>();
|
||||
if (body is NewExpression)
|
||||
{
|
||||
@@ -284,20 +285,9 @@ namespace SqlSugar
|
||||
foreach (var item in arg)
|
||||
{
|
||||
var name=members[index].Name;
|
||||
if (item is MethodCallExpression)
|
||||
if (item is MethodCallExpression)
|
||||
{
|
||||
var method = (item as MethodCallExpression);
|
||||
if (method.Method.Name == "ToList"&&method.Arguments.Count>0&& method.Arguments[0] is MethodCallExpression)
|
||||
{
|
||||
method = (MethodCallExpression)method.Arguments[0];
|
||||
}
|
||||
if (method.Method.Name == "Select")
|
||||
{
|
||||
if (!item.ToString().Contains("Subqueryable"))
|
||||
{
|
||||
result.Add(new NavMappingColumn() { IsError = true });
|
||||
}
|
||||
}
|
||||
AddCallError(result, item, parameterName);
|
||||
}
|
||||
index++;
|
||||
}
|
||||
@@ -309,15 +299,43 @@ namespace SqlSugar
|
||||
MemberAssignment memberAssignment = (MemberAssignment)item;
|
||||
var key= memberAssignment.Member.Name;
|
||||
var value = memberAssignment.Expression;
|
||||
if (memberAssignment.Expression is MemberExpression)
|
||||
if (memberAssignment.Expression is MemberExpression)
|
||||
{
|
||||
result.Add(new NavMappingColumn() { Key=key,Value= ExpressionTool.GetMemberName(memberAssignment.Expression) });
|
||||
result.Add(new NavMappingColumn() { Key = key, Value = ExpressionTool.GetMemberName(memberAssignment.Expression) });
|
||||
}
|
||||
else if(memberAssignment.Expression is MethodCallExpression)
|
||||
{
|
||||
AddCallError(result, memberAssignment.Expression,parameterName);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void AddCallError(List<NavMappingColumn> result, Expression item,string parameterName)
|
||||
{
|
||||
var method = (item as MethodCallExpression);
|
||||
if (method.Method.Name == "ToList" && method.Arguments.Count > 0 && method.Arguments[0] is MethodCallExpression)
|
||||
{
|
||||
method = (MethodCallExpression)method.Arguments[0];
|
||||
}
|
||||
if (method.Method.Name == "Select")
|
||||
{
|
||||
if (!item.ToString().Contains("Subqueryable"))
|
||||
{
|
||||
result.Add(new NavMappingColumn() { IsError = true });
|
||||
}
|
||||
}
|
||||
else if (method.Method.Name == "Join")
|
||||
{
|
||||
|
||||
if (item.ToString().Contains($" {parameterName}."))
|
||||
{
|
||||
result.Add(new NavMappingColumn() { IsError = true });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool isGroup<T, TResult>(Expression<Func<T, TResult>> expression, QueryableProvider<T> queryableProvider)
|
||||
{
|
||||
var isGroup=queryableProvider.QueryBuilder.GetGroupByString.HasValue();
|
||||
|
||||
@@ -451,8 +451,13 @@ namespace SqlSugar
|
||||
var oldValue = verColumn.PropertyInfo.GetValue(updateData);
|
||||
var newValue = UtilMethods.GetRandomByType(verColumn.UnderType);
|
||||
verColumn.PropertyInfo.SetValue(updateData, newValue);
|
||||
var data = this.UpdateBuilder.DbColumnInfoList.First(it =>
|
||||
var data = this.UpdateBuilder.DbColumnInfoList.FirstOrDefault(it =>
|
||||
it.PropertyName.EqualCase(verColumn.PropertyName));
|
||||
if (data == null)
|
||||
{
|
||||
data = new DbColumnInfo() { DbColumnName= verColumn.DbColumnName, Value=newValue };
|
||||
this.UpdateBuilder.DbColumnInfoList.Add(data);
|
||||
}
|
||||
data.Value = newValue;
|
||||
var pks = GetPrimaryKeys();
|
||||
Check.ExceptionEasy(pks.Count == 0, "need primary key or WhereColumn", "需要主键或者WhereColumn");
|
||||
|
||||
@@ -188,7 +188,7 @@ namespace SqlSugar
|
||||
public static DateTime DateAdd(DateTime date, int addValue) { throw new NotSupportedException("Can only be used in expressions"); }
|
||||
public static int DateValue(DateTime date, DateType dataType) { throw new NotSupportedException("Can only be used in expressions"); }
|
||||
public static bool Between(object value, object start, object end) { throw new NotSupportedException("Can only be used in expressions"); }
|
||||
public static TResult IIF<TResult>(bool Expression, TResult thenValue, TResult elseValue) { throw new NotSupportedException("Can only be used in expressions"); }
|
||||
public static TResult IIF<TResult>(bool isTrue, TResult thenValue, TResult elseValue) { return isTrue ? thenValue : elseValue; }
|
||||
public static TResult IsNull<TResult>(TResult thisValue, TResult ifNullValue) { throw new NotSupportedException("Can only be used in expressions"); }
|
||||
public static string MergeString(string value1,string value2) { throw new NotSupportedException("Can only be used in expressions"); }
|
||||
public static string MergeString(string value1, string value2,string value3) { throw new NotSupportedException("Can only be used in expressions"); }
|
||||
|
||||
@@ -38,7 +38,16 @@ namespace SqlSugar
|
||||
public RepositoryType ChangeRepository<RepositoryType>() where RepositoryType : ISugarRepository
|
||||
{
|
||||
Type type = typeof(RepositoryType);
|
||||
object o = Activator.CreateInstance(type,new string[]{ null});
|
||||
var isAnyParamter = type.GetConstructors().Any(z => z.GetParameters().Any());
|
||||
object o = null;
|
||||
if (isAnyParamter)
|
||||
{
|
||||
o=Activator.CreateInstance(type, new string[] { null });
|
||||
}
|
||||
else
|
||||
{
|
||||
o = Activator.CreateInstance(type);
|
||||
}
|
||||
var result= (RepositoryType)o;
|
||||
if (result.Context == null)
|
||||
{
|
||||
|
||||
@@ -136,6 +136,26 @@ namespace SqlSugar
|
||||
{
|
||||
return this.Context.GetSimpleClient<T>();
|
||||
}
|
||||
public RepositoryType GetRepository<RepositoryType>() where RepositoryType : ISugarRepository , new()
|
||||
{
|
||||
Type type = typeof(RepositoryType);
|
||||
var isAnyParamter = type.GetConstructors().Any(z => z.GetParameters().Any());
|
||||
object o = null;
|
||||
if (isAnyParamter)
|
||||
{
|
||||
o = Activator.CreateInstance(type, new string[] { null });
|
||||
}
|
||||
else
|
||||
{
|
||||
o = Activator.CreateInstance(type);
|
||||
}
|
||||
var result = (RepositoryType)o;
|
||||
if (result.Context == null)
|
||||
{
|
||||
result.Context = this.Context;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Insertable
|
||||
|
||||
Reference in New Issue
Block a user