protected override ISqlBuilder Select(MemberInitExpression expression, ISqlBuilder sqlBuilder) { var isHasAnyColumn = false; foreach (MemberAssignment memberAss in expression.Bindings) { isHasAnyColumn = true; var memberExp = memberAss.Expression as MemberExpression; var property = memberExp.Member as PropertyInfo; if (!property.IsDataConlumnProperty(memberExp.Expression.Type)) { continue; } var tablAlias = GetTableAlias(memberExp, sqlBuilder); var columnName = $"{tablAlias}{sqlBuilder.Formate(memberExp.Member.Name)}"; MemberInfo member = memberAss.Member; var fieldName = $"{sqlBuilder.Formate(member.Name)}"; sqlBuilder.AddSelectColumn($"{columnName} {fieldName}"); sqlBuilder.AddSelectPageColumn(fieldName); } if (!isHasAnyColumn) { sqlBuilder.AddSelectColumn("* "); sqlBuilder.AddSelectPageColumn("* "); } return(sqlBuilder); }
private ISelectQueryAble <T> SelectParser(Expression expression, Expression expressionBody, params Type[] types) { _SqlBuilder.SetSqlCommandType(SqlCommandType.Select); _SqlBuilder.SetTableAlias(_MainTableName); _SqlBuilder.AppendSelectSql($"SELECT {{0}} FROM {_MainTableName} {_SqlBuilder.GetTableAlias(_MainTableName)} "); var selectQueryAble = new SelectQueryAble <T>(_SqlBuilder, _DapperKitProvider); if (expression != null && expressionBody != null) { if (types != null && types.Length > 0) { _SqlBuilder.SetSelectMultiTable(); foreach (var type in types) { string tableName = type.GetDapperTableName(_SqlBuilder._SqlFormater); _SqlBuilder.SetTableAlias(tableName); //add data table type to collection selectQueryAble.TableTypeCollections.Add(type); } } SqlVistorProvider.Select(expressionBody, _SqlBuilder); } else { _SqlBuilder.AddSelectColumn("* "); _SqlBuilder.AddSelectPageColumn("* "); } return(selectQueryAble); }
protected override ISqlBuilder Select(NewExpression expression, ISqlBuilder sqlBuilder) { for (int i = 0; i < expression.Arguments.Count; i++) { var argument = expression.Arguments[i]; var mermberExp = ((MemberExpression)argument); PropertyInfo property = mermberExp.Member as PropertyInfo; if (!property.IsDataConlumnProperty(mermberExp.Expression.Type)) { continue; } //get table name var tableName = mermberExp.Member.DeclaringType.GetDapperTableName(sqlBuilder._SqlFormater); string tableAlias = sqlBuilder.GetTableAlias(tableName); if (!string.IsNullOrWhiteSpace(tableAlias)) { tableAlias = $"{tableAlias}."; } //get table column name var columnName = $"{tableAlias}{sqlBuilder.Formate(mermberExp.Member.Name)}"; //get data column name var fieldName = $"{sqlBuilder.Formate(expression.Members[i].Name)}"; sqlBuilder.AddSelectColumn($"{columnName} {fieldName}"); sqlBuilder.AddSelectPageColumn(fieldName); } return(sqlBuilder); }
protected override ISqlBuilder Select(MemberExpression expression, ISqlBuilder sqlBuilder) { PropertyInfo propertyInfo = expression.Member as PropertyInfo; if (!propertyInfo.IsDataConlumnProperty(expression.Member.DeclaringType)) { throw new Exception($"{ expression.Member.Name } is not data column"); } var tableAlias = GetTableAlias(expression, sqlBuilder); //get table column name var columnName = $"{tableAlias}{sqlBuilder.Formate(expression.Member.Name)}"; //get data column name var fieldName = $"{sqlBuilder.Formate(expression.Member.Name)}"; sqlBuilder.AddSelectColumn($"{columnName} {fieldName}"); sqlBuilder.AddSelectPageColumn(fieldName); return(sqlBuilder); }