diff --git a/Src/Asp.Net/SqlServerTest/Demo/Demo9_EntityMain.cs b/Src/Asp.Net/SqlServerTest/Demo/Demo9_EntityMain.cs index 338898d9b..be795b098 100644 --- a/Src/Asp.Net/SqlServerTest/Demo/Demo9_EntityMain.cs +++ b/Src/Asp.Net/SqlServerTest/Demo/Demo9_EntityMain.cs @@ -34,6 +34,11 @@ namespace OrmTest { Console.WriteLine(column.DbColumnName); } + + var dbColumnsName = db.EntityMaintenance.GetDbColumnName("Name"); + + var dbTableName = db.EntityMaintenance.GetTableName(); + //more https://github.com/sunkaixuan/SqlSugar/wiki/9.EntityMain Console.WriteLine("#### EntityMain End ####"); } diff --git a/Src/Asp.Net/SqlServerTest/Models/EntityMapper.cs b/Src/Asp.Net/SqlServerTest/Models/EntityMapper.cs new file mode 100644 index 000000000..b597012fb --- /dev/null +++ b/Src/Asp.Net/SqlServerTest/Models/EntityMapper.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SqlSugar; +namespace OrmTest +{ + [SugarTable("MyEntityMapper")] + public class EntityMapper + { + [SugarColumn(ColumnName ="MyName")] + public string Name { get; set; } + } +} diff --git a/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj b/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj index 13c29477d..7d10470ae 100644 --- a/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj +++ b/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj @@ -68,6 +68,7 @@ + diff --git a/Src/Asp.Net/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs b/Src/Asp.Net/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs index 0661b6665..21016b96f 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs @@ -46,7 +46,12 @@ namespace SqlSugar public string GetTableName() { var typeName = typeof(T).Name; - if (this.Context.MappingTables == null || this.Context.MappingTables.Count == 0) return typeName; + if (this.Context.MappingTables == null || this.Context.MappingTables.Count == 0) + { + var entity = this.GetEntityInfo(); + if (entity.DbTableName.HasValue()) return entity.DbTableName; + else return entity.EntityName; + } else { var mappingInfo = this.Context.MappingTables.SingleOrDefault(it => it.EntityName == typeName); @@ -56,7 +61,12 @@ namespace SqlSugar public string GetTableName(Type entityType) { var typeName = entityType.Name; - if (this.Context.MappingTables == null || this.Context.MappingTables.Count == 0) return typeName; + if (this.Context.MappingTables == null || this.Context.MappingTables.Count == 0) + { + var entity = this.GetEntityInfo(entityType); + if (entity.DbTableName.HasValue()) return entity.DbTableName; + else return entity.EntityName; + } else { var mappingInfo = this.Context.MappingTables.SingleOrDefault(it => it.EntityName == typeName); @@ -87,7 +97,12 @@ namespace SqlSugar var isAny = this.GetEntityInfo().Columns.Any(it => it.PropertyName.Equals(propertyName, StringComparison.CurrentCultureIgnoreCase)); Check.Exception(!isAny, "Property " + propertyName + " is Invalid"); var typeName = typeof(T).Name; - if (this.Context.MappingColumns == null || this.Context.MappingColumns.Count == 0) return propertyName; + if (this.Context.MappingColumns == null || this.Context.MappingColumns.Count == 0) + { + var column= this.GetEntityInfo().Columns.First(it => it.PropertyName.Equals(propertyName, StringComparison.CurrentCultureIgnoreCase)); + if (column.DbColumnName.HasValue()) return column.DbColumnName; + else return column.PropertyName; + } else { var mappingInfo = this.Context.MappingColumns.SingleOrDefault(it => it.EntityName == typeName && it.PropertyName == propertyName); @@ -99,7 +114,12 @@ namespace SqlSugar var isAny = this.GetEntityInfo(entityType).Columns.Any(it => it.PropertyName.Equals(propertyName, StringComparison.CurrentCultureIgnoreCase)); Check.Exception(!isAny, "Property " + propertyName + " is Invalid"); var typeName = entityType.Name; - if (this.Context.MappingColumns == null || this.Context.MappingColumns.Count == 0) return propertyName; + if (this.Context.MappingColumns == null || this.Context.MappingColumns.Count == 0) + { + var column = this.GetEntityInfo(entityType).Columns.First(it => it.PropertyName.Equals(propertyName, StringComparison.CurrentCultureIgnoreCase)); + if (column.DbColumnName.HasValue()) return column.DbColumnName; + else return column.PropertyName; + } else { var mappingInfo = this.Context.MappingColumns.SingleOrDefault(it => it.EntityName == typeName && it.PropertyName == propertyName);