/// <summary> /// 连表 /// </summary> /// <typeparam name="TInner">副表</typeparam> /// <param name="expression">条件</param> /// <param name="joinMode">连接类型</param> /// <param name="isDisField">是否需要显示表字段</param> /// <returns></returns> public QuerySet <T> Join <TInner>(LambdaExpression expression, JoinMode joinMode = JoinMode.LEFT, bool isDisField = true) { var joinWhere = new WhereExpression(expression, $"{Params.ParameterNames.Count()}", SqlProvider); Regex whereRex = new Regex("AND"); string tableName = SqlProvider.FormatTableName(false, true, typeof(TInner)); SqlProvider.JoinList.Add(new JoinAssTable() { Action = JoinAction.Sql, JoinSql = $"{joinMode.ToString()} JOIN {tableName} ON { whereRex.Replace(joinWhere.SqlCmd, "", 1)}", TableType = (isDisField ? typeof(TInner) : null) }); if (joinWhere.Param != null) { Params.AddDynamicParams(joinWhere.Param, true); } return(this); }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="tValue></param> /// <param name="excludeFields">排除字段</param> /// <param name="index">当前数据索引</param> /// <returns></returns> private Tuple <string, StringBuilder, StringBuilder, DynamicParameters> ResolveInsertParamsAndValues <T>(T tValue, string[] excludeFields = null, int index = 0) { var fieldBuilder = new StringBuilder(64); var paramBuilder = new StringBuilder(64); DynamicParameters parameters = new DynamicParameters(); var entityProperties = EntityCache.QueryEntity(typeof(T)); var tableName = provider.FormatTableName(false, false); // entityProperties.Name; var isAppend = false; foreach (var entityField in entityProperties.EntityFieldList) { string fieldName = entityField.FieldName; //是否是排除字段 if (excludeFields != null && (excludeFields.Contains(fieldName) || excludeFields.Contains(entityField.PropertyInfo.Name))) { continue; } //是否自增 if (entityField.IsIncrease) { continue; } if (isAppend) { fieldBuilder.Append(","); paramBuilder.Append(","); } //字段添加 fieldBuilder.Append($"{fieldName}"); //参数添加 paramBuilder.Append($"{provider.ProviderOption.ParameterPrefix}{fieldName}{index}"); parameters.Add($"{provider.ProviderOption.ParameterPrefix}{fieldName}{index}", entityField.PropertyInfo.GetValue(tValue)); isAppend = true; } return(new Tuple <string, StringBuilder, StringBuilder, DynamicParameters>(tableName, fieldBuilder, paramBuilder, parameters)); }