mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-19 18:22:23 +08:00
Synchronization code
This commit is contained in:
@@ -504,6 +504,10 @@ namespace SqlSugar
|
|||||||
childDb.InitMappingInfo(navEntity);
|
childDb.InitMappingInfo(navEntity);
|
||||||
var navEntityInfo = childDb.EntityMaintenance.GetEntityInfo(navEntity);
|
var navEntityInfo = childDb.EntityMaintenance.GetEntityInfo(navEntity);
|
||||||
var sqlObj = GetWhereSql(navObjectNameColumnInfo.Navigat.Name);
|
var sqlObj = GetWhereSql(navObjectNameColumnInfo.Navigat.Name);
|
||||||
|
if (IsJsonMapping(navObjectNameColumnInfo, sqlObj))
|
||||||
|
{
|
||||||
|
CreateDynamicMappingExpression(sqlObj, navObjectNameColumnInfo.Navigat.Name, navEntityInfo, listItemEntity);
|
||||||
|
}
|
||||||
Check.ExceptionEasy(sqlObj.MappingExpressions.IsNullOrEmpty(), $"{expression} error,dynamic need MappingField ,Demo: Includes(it => it.Books.MappingField(z=>z.studenId,()=>it.StudentId).ToList())", $"{expression} 解析出错,自定义映射需要 MappingField ,例子: Includes(it => it.Books.MappingField(z=>z.studenId,()=>it.StudentId).ToList())");
|
Check.ExceptionEasy(sqlObj.MappingExpressions.IsNullOrEmpty(), $"{expression} error,dynamic need MappingField ,Demo: Includes(it => it.Books.MappingField(z=>z.studenId,()=>it.StudentId).ToList())", $"{expression} 解析出错,自定义映射需要 MappingField ,例子: Includes(it => it.Books.MappingField(z=>z.studenId,()=>it.StudentId).ToList())");
|
||||||
if (list.Any() && navObjectNamePropety.GetValue(list.First()) == null)
|
if (list.Any() && navObjectNamePropety.GetValue(list.First()) == null)
|
||||||
{
|
{
|
||||||
@@ -530,6 +534,10 @@ namespace SqlSugar
|
|||||||
var navEntityInfo = this.Context.EntityMaintenance.GetEntityInfo(navEntity);
|
var navEntityInfo = this.Context.EntityMaintenance.GetEntityInfo(navEntity);
|
||||||
this.Context.InitMappingInfo(navEntity);
|
this.Context.InitMappingInfo(navEntity);
|
||||||
var sqlObj = GetWhereSql(navObjectNameColumnInfo.Navigat.Name);
|
var sqlObj = GetWhereSql(navObjectNameColumnInfo.Navigat.Name);
|
||||||
|
if (IsJsonMapping(navObjectNameColumnInfo, sqlObj))
|
||||||
|
{
|
||||||
|
CreateDynamicMappingExpression(sqlObj, navObjectNameColumnInfo.Navigat.Name, navEntityInfo, listItemEntity);
|
||||||
|
}
|
||||||
Check.ExceptionEasy(sqlObj.MappingExpressions.IsNullOrEmpty(), $"{expression} error,dynamic need MappingField ,Demo: Includes(it => it.Books.MappingField(z=>z.studenId,()=>it.StudentId).ToList())", $"{expression}解析出错, 自定义映射需要 MappingField ,例子: Includes(it => it.Books.MappingField(z=>z.studenId,()=>it.StudentId).ToList())");
|
Check.ExceptionEasy(sqlObj.MappingExpressions.IsNullOrEmpty(), $"{expression} error,dynamic need MappingField ,Demo: Includes(it => it.Books.MappingField(z=>z.studenId,()=>it.StudentId).ToList())", $"{expression}解析出错, 自定义映射需要 MappingField ,例子: Includes(it => it.Books.MappingField(z=>z.studenId,()=>it.StudentId).ToList())");
|
||||||
if (list.Any() && navObjectNamePropety.GetValue(list.First()) == null)
|
if (list.Any() && navObjectNamePropety.GetValue(list.First()) == null)
|
||||||
{
|
{
|
||||||
@@ -846,5 +854,31 @@ namespace SqlSugar
|
|||||||
navPkColumn?.SqlParameterDbType == null &&
|
navPkColumn?.SqlParameterDbType == null &&
|
||||||
this.Context?.CurrentConnectionConfig?.MoreSettings?.TableEnumIsString != true;
|
this.Context?.CurrentConnectionConfig?.MoreSettings?.TableEnumIsString != true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool IsJsonMapping(EntityColumnInfo navObjectNameColumnInfo, SqlInfo sqlObj)
|
||||||
|
{
|
||||||
|
return sqlObj.MappingExpressions == null && navObjectNameColumnInfo.Navigat.Name.HasValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CreateDynamicMappingExpression(SqlInfo sqlObj, string name, EntityInfo navEntityInfo, EntityInfo listItemEntity)
|
||||||
|
{
|
||||||
|
var json = Newtonsoft.Json.Linq.JArray.Parse(name);
|
||||||
|
sqlObj.MappingExpressions = new List<MappingFieldsExpression>();
|
||||||
|
foreach (var item in json)
|
||||||
|
{
|
||||||
|
string m = item["m"]+"";
|
||||||
|
string c = item["c"] + "";
|
||||||
|
Check.ExceptionEasy(m.IsNullOrEmpty() || c.IsNullOrEmpty(), $"{name} Navigation json format error, see documentation", $"{name}导航json格式错误,请看文档");
|
||||||
|
var cColumn= navEntityInfo.Columns.FirstOrDefault(it => it.PropertyName.EqualCase(c));
|
||||||
|
Check.ExceptionEasy(cColumn==null, $"{c} does not exist in {navEntityInfo.EntityName}", $"{c}不存在于{navEntityInfo.EntityName}");
|
||||||
|
var mColumn = listItemEntity.Columns.FirstOrDefault(it => it.PropertyName.EqualCase(m));
|
||||||
|
Check.ExceptionEasy(cColumn == null, $"{m} does not exist in {listItemEntity.EntityName}", $"{m}不存在于{listItemEntity.EntityName}");
|
||||||
|
sqlObj.MappingExpressions.Add(new MappingFieldsExpression() {
|
||||||
|
|
||||||
|
LeftEntityColumn = cColumn,
|
||||||
|
RightEntityColumn = mColumn,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1339,6 +1339,15 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
return _Select<TResult>(expression);
|
return _Select<TResult>(expression);
|
||||||
}
|
}
|
||||||
|
public ISugarQueryable<TResult> Select<TResult>(string expShortName, FormattableString expSelect, Type propertyType)
|
||||||
|
{
|
||||||
|
var exp = DynamicCoreHelper.GetMember(typeof(TResult),propertyType, expShortName, expSelect);
|
||||||
|
return _Select<TResult>(exp);
|
||||||
|
}
|
||||||
|
public ISugarQueryable<T> Select(string expShortName, FormattableString expSelect,Type propertyType)
|
||||||
|
{
|
||||||
|
return Select<T>(expShortName, expSelect, propertyType);
|
||||||
|
}
|
||||||
public virtual ISugarQueryable<TResult> Select<TResult>(Expression<Func<T, TResult>> expression)
|
public virtual ISugarQueryable<TResult> Select<TResult>(Expression<Func<T, TResult>> expression)
|
||||||
{
|
{
|
||||||
if (IsAppendNavColumns())
|
if (IsAppendNavColumns())
|
||||||
|
@@ -151,6 +151,8 @@ namespace SqlSugar
|
|||||||
Task<bool> AnyAsync(Expression<Func<T, bool>> expression, CancellationToken token);
|
Task<bool> AnyAsync(Expression<Func<T, bool>> expression, CancellationToken token);
|
||||||
bool Any();
|
bool Any();
|
||||||
Task<bool> AnyAsync();
|
Task<bool> AnyAsync();
|
||||||
|
ISugarQueryable<TResult> Select<TResult>(string expShortName, FormattableString expSelect, Type propertyType);
|
||||||
|
ISugarQueryable<T> Select(string expShortName, FormattableString expSelect, Type propertyType);
|
||||||
ISugarQueryable<TResult> Select<TResult>(Expression expression);
|
ISugarQueryable<TResult> Select<TResult>(Expression expression);
|
||||||
ISugarQueryable<TResult> Select<TResult>(Expression<Func<T, TResult>> expression);
|
ISugarQueryable<TResult> Select<TResult>(Expression<Func<T, TResult>> expression);
|
||||||
ISugarQueryable<TResult> Select<TResult>(Expression<Func<T, TResult>> expression,bool isAutoFill);
|
ISugarQueryable<TResult> Select<TResult>(Expression<Func<T, TResult>> expression,bool isAutoFill);
|
||||||
|
@@ -32,6 +32,26 @@ namespace SqlSugar
|
|||||||
|
|
||||||
return lambda;
|
return lambda;
|
||||||
}
|
}
|
||||||
|
public static LambdaExpression GetMember(Type entityType,Type propertyType, string shortName, FormattableString memberSql)
|
||||||
|
{
|
||||||
|
var parameter = Expression.Parameter(entityType, "it");
|
||||||
|
|
||||||
|
// 提取 FormattableString 中的参数值
|
||||||
|
var arguments = memberSql.GetArguments();
|
||||||
|
|
||||||
|
|
||||||
|
var sql = ReplaceFormatParameters(memberSql.Format);
|
||||||
|
|
||||||
|
// 构建动态表达式,使用常量表达式和 whereSql 中的参数值
|
||||||
|
var lambda = SqlSugarDynamicExpressionParser.ParseLambda(
|
||||||
|
new[] { parameter },
|
||||||
|
propertyType,
|
||||||
|
sql,
|
||||||
|
memberSql.GetArguments()
|
||||||
|
);
|
||||||
|
|
||||||
|
return lambda;
|
||||||
|
}
|
||||||
private static string ReplaceFormatParameters(string format)
|
private static string ReplaceFormatParameters(string format)
|
||||||
{
|
{
|
||||||
int parameterIndex = 0; // 起始参数索引
|
int parameterIndex = 0; // 起始参数索引
|
||||||
|
Reference in New Issue
Block a user