diff --git a/Src/Asp.Net/SqlSugar/Entities/JoinMapper.cs b/Src/Asp.Net/SqlSugar/Entities/JoinMapper.cs new file mode 100644 index 000000000..b45d7729e --- /dev/null +++ b/Src/Asp.Net/SqlSugar/Entities/JoinMapper.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SqlSugar +{ + internal class JoinMapper + { + public string asName { get; set; } + public string dbName { get; set; } + } +} diff --git a/Src/Asp.Net/SqlSugar/Infrastructure/Mapper.cs b/Src/Asp.Net/SqlSugar/Infrastructure/Mapper.cs index c8bb72b8c..0577d20d0 100644 --- a/Src/Asp.Net/SqlSugar/Infrastructure/Mapper.cs +++ b/Src/Asp.Net/SqlSugar/Infrastructure/Mapper.cs @@ -20,85 +20,45 @@ namespace SqlSugar var veiwModel = _context.EntityMaintenance.GetEntityInfo(); var exp = (queryBuilder.JoinExpression as LambdaExpression); List> selectItems = new List>(); - foreach (var viewColumn in veiwModel.Columns) + var exParsmeters = exp.Parameters.Select(it => new { shortName = it.Name, type = it.Type }).ToList(); + foreach (var viewColumns in veiwModel.Columns) { - var exParsmeters = exp.Parameters.Select(it => new { shortName = it.Name, type = it.Type }).ToList(); + var isbreak = false; foreach (var expPars in exParsmeters) - { - var columns = _context.EntityMaintenance.GetEntityInfo(expPars.type).Columns.Where(it => it.IsIgnore == false); - var joinModelDbColumns = columns.Select(it => - new { asName = it.PropertyName, dbName = _context.EntityMaintenance.GetDbColumnName(it.PropertyName, expPars.type) }).ToList(); - var joinModelProperties = columns.Select(it => - new { asName = _context.EntityMaintenance.GetDbColumnName(it.PropertyName, expPars.type), dbName = _context.EntityMaintenance.GetDbColumnName(it.PropertyName, expPars.type) }).ToList(); - var joinModelDbColumnsWithType = columns.Select(it => - new { asName = (expPars.type.Name + it.PropertyName), dbName = _context.EntityMaintenance.GetDbColumnName(it.PropertyName, expPars.type) }).ToList(); - var joinModelPropertiesWithTye = columns.Select(it => - new { asName = (expPars.type.Name + _context.EntityMaintenance.GetDbColumnName(it.PropertyName, expPars.type)), dbName = _context.EntityMaintenance.GetDbColumnName(it.PropertyName, expPars.type) }).ToList(); - var joinModelDbColumns_WithType = columns.Select(it => - new { asName = (expPars.type.Name +"_"+ it.PropertyName), dbName = _context.EntityMaintenance.GetDbColumnName(it.PropertyName, expPars.type) }).ToList(); - var joinModelProperties_WithType = columns.Select(it => - new { asName = (expPars.type.Name +"_"+ _context.EntityMaintenance.GetDbColumnName(it.PropertyName, expPars.type)), dbName = _context.EntityMaintenance.GetDbColumnName(it.PropertyName, expPars.type) }).ToList(); - var joinModelDbColumnsWithSN = columns.Select(it => - new { asName = (expPars.shortName + it.PropertyName), dbName = _context.EntityMaintenance.GetDbColumnName(it.PropertyName, expPars.type) }).ToList(); - var joinModelPropertiesWithSN = columns.Select(it => - new { asName = (expPars.shortName + _context.EntityMaintenance.GetDbColumnName(it.PropertyName, expPars.type)), dbName = _context.EntityMaintenance.GetDbColumnName(it.PropertyName, expPars.type) }).ToList(); - - if (joinModelDbColumns.Any(it => it.asName.Equals(viewColumn.PropertyName,StringComparison.CurrentCultureIgnoreCase))) - { - var value = joinModelDbColumns.First(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase)); - if (viewColumn.PropertyName.Equals(value.asName, StringComparison.CurrentCultureIgnoreCase)) - selectItems.Add(new KeyValuePair(expPars.shortName,value)); - break; - } - if (joinModelProperties.Any(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase))) + { + if (isbreak) { - var value = joinModelProperties.First(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase)); - if (viewColumn.PropertyName.Equals(value.asName, StringComparison.CurrentCultureIgnoreCase)) - selectItems.Add(new KeyValuePair(expPars.shortName, value)); - break; - } - if (joinModelDbColumnsWithType.Any(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase))) - { - var value = joinModelDbColumnsWithType.First(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase)); - if (viewColumn.PropertyName.Equals(value.asName, StringComparison.CurrentCultureIgnoreCase)) - selectItems.Add(new KeyValuePair(expPars.shortName, value)); - break; - } - if (joinModelPropertiesWithTye.Any(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase))) - { - var value = joinModelPropertiesWithTye.First(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase)); - if (viewColumn.PropertyName.Equals(value.asName, StringComparison.CurrentCultureIgnoreCase)) - selectItems.Add(new KeyValuePair(expPars.shortName, value)); break; } + var entityInfo = _context.EntityMaintenance.GetEntityInfo(expPars.type); + var columns = entityInfo.Columns.Where(it => it.IsIgnore == false); + var list = columns.Select(it => { + var array = new string[] + { + it.PropertyName, + it.DbColumnName, - if (joinModelDbColumns_WithType.Any(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase))) - { - var value = joinModelDbColumns_WithType.First(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase)); - if (viewColumn.PropertyName.Equals(value.asName, StringComparison.CurrentCultureIgnoreCase)) - selectItems.Add(new KeyValuePair(expPars.shortName, value)); - break; - } - if (joinModelProperties_WithType.Any(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase))) - { - var value = joinModelProperties_WithType.First(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase)); - if (viewColumn.PropertyName.Equals(value.asName, StringComparison.CurrentCultureIgnoreCase)) - selectItems.Add(new KeyValuePair(expPars.shortName, value)); - break; - } - if (joinModelDbColumnsWithSN.Any(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase))) - { - var value = joinModelDbColumnsWithSN.First(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase)); - if (viewColumn.PropertyName.Equals(value.asName, StringComparison.CurrentCultureIgnoreCase)) - selectItems.Add(new KeyValuePair(expPars.shortName, value)); - break; - } - if (joinModelPropertiesWithSN.Any(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase))) + expPars.type.Name+it.PropertyName, + expPars.type.Name+it.DbColumnName, + + expPars.type.Name+"_"+it.PropertyName, + expPars.type.Name+"_"+it.DbColumnName, + + expPars.shortName+it.PropertyName, + expPars.shortName+it.DbColumnName, + }; + return new { it, array }; + }).ToList(); + var columnInfo= list.FirstOrDefault(y => y.array.Select(z=>z.ToLower()).Contains(viewColumns.PropertyName.ToLower())); + if (columnInfo != null) { - var value = joinModelPropertiesWithSN.First(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase)); - if (viewColumn.PropertyName.Equals(value.asName, StringComparison.CurrentCultureIgnoreCase)) - selectItems.Add(new KeyValuePair(expPars.shortName, value)); - break; + JoinMapper joinMapper = new JoinMapper() + { + asName=viewColumns.PropertyName, + dbName=columnInfo.it.DbColumnName + }; + selectItems.Add(new KeyValuePair(expPars.shortName,joinMapper)); + isbreak = true; } } } diff --git a/Src/Asp.Net/SqlSugar/SqlSugar.csproj b/Src/Asp.Net/SqlSugar/SqlSugar.csproj index 6f391c58e..58d3a0451 100644 --- a/Src/Asp.Net/SqlSugar/SqlSugar.csproj +++ b/Src/Asp.Net/SqlSugar/SqlSugar.csproj @@ -96,6 +96,7 @@ +