mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 22:11:36 +08:00
-
This commit is contained in:
parent
d80ce8c345
commit
bd76f0dc29
@ -35,5 +35,44 @@ namespace SqlSugar
|
||||
return result;
|
||||
});
|
||||
}
|
||||
public string GetTableName<T>()
|
||||
{
|
||||
var typeName = typeof(T).Name;
|
||||
if (this.Context.MappingTables == null || this.Context.MappingTables.Count == 0) return typeName;
|
||||
else
|
||||
{
|
||||
var mappingInfo = this.Context.MappingTables.SingleOrDefault(it => it.EntityName == typeName);
|
||||
return mappingInfo == null ? typeName : mappingInfo.DbTableName;
|
||||
}
|
||||
}
|
||||
public string GetEntityName(string tableName)
|
||||
{
|
||||
if (this.Context.MappingTables == null || this.Context.MappingTables.Count == 0) return tableName;
|
||||
else
|
||||
{
|
||||
var mappingInfo = this.Context.MappingTables.SingleOrDefault(it => it.DbTableName == tableName);
|
||||
return mappingInfo == null ? tableName : mappingInfo.EntityName;
|
||||
}
|
||||
}
|
||||
public string GetDbColumnName<T>(string entityPropertyName)
|
||||
{
|
||||
var typeName = typeof(T).Name;
|
||||
if (this.Context.MappingColumns == null || this.Context.MappingColumns.Count == 0) return entityPropertyName;
|
||||
else
|
||||
{
|
||||
var mappingInfo = this.Context.MappingColumns.SingleOrDefault(it => it.EntityName == typeName && it.EntityPropertyName == entityPropertyName);
|
||||
return mappingInfo == null ? entityPropertyName : mappingInfo.DbColumnName;
|
||||
}
|
||||
}
|
||||
public string GetEntityPropertyName<T>(string dbColumnName)
|
||||
{
|
||||
var typeName = typeof(T).Name;
|
||||
if (this.Context.MappingColumns == null || this.Context.MappingColumns.Count == 0) return dbColumnName;
|
||||
else
|
||||
{
|
||||
var mappingInfo = this.Context.MappingColumns.SingleOrDefault(it => it.EntityName == typeName && it.DbColumnName == dbColumnName);
|
||||
return mappingInfo == null ? dbColumnName : mappingInfo.DbColumnName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ namespace SqlSugar
|
||||
Where("1=2 ");
|
||||
return this;
|
||||
}
|
||||
string tableName = this.Context.GetTableName<T>();
|
||||
string tableName = this.Context.EntityProvider.GetTableName<T>();
|
||||
var entityInfo = this.Context.EntityProvider.GetEntityInfo<T>();
|
||||
if (this.Context.IsSystemTablesConfig)
|
||||
{
|
||||
@ -40,7 +40,7 @@ namespace SqlSugar
|
||||
var primaryField = primaryFields.Single();
|
||||
foreach (var deleteObj in deleteObjs)
|
||||
{
|
||||
var entityPropertyName = this.Context.GetEntityPropertyName<T>(primaryField);
|
||||
var entityPropertyName = this.Context.EntityProvider.GetEntityPropertyName<T>(primaryField);
|
||||
var columnInfo = entityInfo.Columns.Single(it => it.Name == entityPropertyName);
|
||||
var value = columnInfo.PropertyInfo.GetValue(deleteObj, null);
|
||||
primaryKeyValues.Add(value);
|
||||
@ -65,7 +65,7 @@ namespace SqlSugar
|
||||
{
|
||||
if (i == 0)
|
||||
andString.Append(DeleteBuilder.WhereInAndTemplate + PubConst.Space);
|
||||
var entityPropertyName = this.Context.GetEntityPropertyName<T>(primaryField);
|
||||
var entityPropertyName = this.Context.EntityProvider.GetEntityPropertyName<T>(primaryField);
|
||||
var columnInfo = entityInfo.Columns.Single(it => it.Name == entityPropertyName);
|
||||
var entityValue = columnInfo.PropertyInfo.GetValue(deleteObj, null);
|
||||
andString.AppendFormat(DeleteBuilder.WhereInEqualTemplate, primaryField, entityValue);
|
||||
@ -122,7 +122,7 @@ namespace SqlSugar
|
||||
Where("1=2 ");
|
||||
return this;
|
||||
}
|
||||
string tableName = this.Context.GetTableName<T>();
|
||||
string tableName = this.Context.EntityProvider.GetTableName<T>();
|
||||
string primaryField = null;
|
||||
if (this.Context.IsSystemTablesConfig)
|
||||
{
|
||||
@ -151,7 +151,7 @@ namespace SqlSugar
|
||||
|
||||
public KeyValuePair<string, List<SugarParameter>> ToSql()
|
||||
{
|
||||
DeleteBuilder.TableName = this.Context.GetTableName<T>();
|
||||
DeleteBuilder.TableName = this.Context.EntityProvider.GetTableName<T>();
|
||||
string sql = DeleteBuilder.ToSqlString();
|
||||
var paramters = DeleteBuilder.Parameters == null ? null : DeleteBuilder.Parameters.ToList();
|
||||
return new KeyValuePair<string, List<SugarParameter>>(sql, paramters);
|
||||
|
@ -327,6 +327,7 @@ namespace SqlSugar
|
||||
if (base._EntityProvider == null)
|
||||
{
|
||||
base._EntityProvider = new EntityProvider();
|
||||
base._EntityProvider.Context = this;
|
||||
}
|
||||
return _EntityProvider;
|
||||
}
|
||||
@ -353,47 +354,5 @@ namespace SqlSugar
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Internal Methods
|
||||
internal string GetTableName<T>()
|
||||
{
|
||||
var typeName = typeof(T).Name;
|
||||
if (this.MappingTables == null || this.MappingTables.Count == 0) return typeName;
|
||||
else
|
||||
{
|
||||
var mappingInfo = this.MappingTables.SingleOrDefault(it => it.EntityName == typeName);
|
||||
return mappingInfo==null?typeName:mappingInfo.DbTableName;
|
||||
}
|
||||
}
|
||||
internal string GetEntityName(string tableName)
|
||||
{
|
||||
if (this.MappingTables == null || this.MappingTables.Count == 0) return tableName;
|
||||
else
|
||||
{
|
||||
var mappingInfo = this.MappingTables.SingleOrDefault(it => it.DbTableName == tableName);
|
||||
return mappingInfo==null?tableName:mappingInfo.EntityName;
|
||||
}
|
||||
}
|
||||
internal string GetDbColumnName<T>(string entityPropertyName)
|
||||
{
|
||||
var typeName = typeof(T).Name;
|
||||
if (this.MappingColumns == null || this.MappingColumns.Count == 0) return entityPropertyName;
|
||||
else
|
||||
{
|
||||
var mappingInfo = this.MappingColumns.SingleOrDefault(it =>it.EntityName==typeName &&it.EntityPropertyName == entityPropertyName);
|
||||
return mappingInfo==null?entityPropertyName:mappingInfo.DbColumnName;
|
||||
}
|
||||
}
|
||||
internal string GetEntityPropertyName<T>(string dbColumnName)
|
||||
{
|
||||
var typeName = typeof(T).Name;
|
||||
if (this.MappingColumns == null || this.MappingColumns.Count == 0) return dbColumnName;
|
||||
else
|
||||
{
|
||||
var mappingInfo = this.MappingColumns.SingleOrDefault(it => it.EntityName == typeName && it.DbColumnName == dbColumnName);
|
||||
return mappingInfo == null ? dbColumnName : mappingInfo.DbColumnName;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user