Update demo

This commit is contained in:
sunkaixuan 2019-06-04 12:30:21 +08:00
parent 3ae7f9fecb
commit b6a747dbf2
4 changed files with 45 additions and 4 deletions

View File

@ -34,6 +34,11 @@ namespace OrmTest
{
Console.WriteLine(column.DbColumnName);
}
var dbColumnsName = db.EntityMaintenance.GetDbColumnName<EntityMapper>("Name");
var dbTableName = db.EntityMaintenance.GetTableName<EntityMapper>();
//more https://github.com/sunkaixuan/SqlSugar/wiki/9.EntityMain
Console.WriteLine("#### EntityMain End ####");
}

View File

@ -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; }
}
}

View File

@ -68,6 +68,7 @@
<Compile Include="Demo\DemoF_Utilities.cs" />
<Compile Include="Demo\DemoG_SimpleClient.cs" />
<Compile Include="Models\Custom.cs" />
<Compile Include="Models\EntityMapper.cs" />
<Compile Include="Models\Mapper.cs" />
<Compile Include="Models\Tree.cs" />
<Compile Include="Models\AttributeTable.cs" />

View File

@ -46,7 +46,12 @@ namespace SqlSugar
public string GetTableName<T>()
{
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<T>();
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<T>().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<T>().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);