mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-20 02:29:39 +08:00
Add db.CodeFirst.As(string newTableName)
This commit is contained in:
@@ -14,6 +14,7 @@ namespace SqlSugar
|
|||||||
protected bool IsBackupTable { get; set; }
|
protected bool IsBackupTable { get; set; }
|
||||||
protected int MaxBackupDataRows { get; set; }
|
protected int MaxBackupDataRows { get; set; }
|
||||||
protected virtual int DefultLength { get; set; }
|
protected virtual int DefultLength { get; set; }
|
||||||
|
protected Dictionary<Type, string> MappingTables = new Dictionary<Type, string>();
|
||||||
public CodeFirstProvider()
|
public CodeFirstProvider()
|
||||||
{
|
{
|
||||||
if (DefultLength == 0)
|
if (DefultLength == 0)
|
||||||
@@ -107,6 +108,19 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public ICodeFirst As(Type type, string newTableName)
|
||||||
|
{
|
||||||
|
if (!MappingTables.ContainsKey(type))
|
||||||
|
{
|
||||||
|
MappingTables.Add(type,newTableName);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public ICodeFirst As<T>(string newTableName)
|
||||||
|
{
|
||||||
|
return As(typeof(T),newTableName);
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void InitTables(string entitiesNamespace)
|
public virtual void InitTables(string entitiesNamespace)
|
||||||
{
|
{
|
||||||
var types = Assembly.Load(entitiesNamespace).GetTypes();
|
var types = Assembly.Load(entitiesNamespace).GetTypes();
|
||||||
@@ -180,6 +194,11 @@ namespace SqlSugar
|
|||||||
protected virtual void Execute(Type entityType)
|
protected virtual void Execute(Type entityType)
|
||||||
{
|
{
|
||||||
var entityInfo = this.Context.EntityMaintenance.GetEntityInfoNoCache(entityType);
|
var entityInfo = this.Context.EntityMaintenance.GetEntityInfoNoCache(entityType);
|
||||||
|
if (this.MappingTables.ContainsKey(entityType))
|
||||||
|
{
|
||||||
|
entityInfo.DbTableName = this.MappingTables[entityType];
|
||||||
|
this.Context.MappingTables.Add(entityInfo.EntityName, entityInfo.DbTableName);
|
||||||
|
}
|
||||||
if (this.DefultLength > 0)
|
if (this.DefultLength > 0)
|
||||||
{
|
{
|
||||||
foreach (var item in entityInfo.Columns)
|
foreach (var item in entityInfo.Columns)
|
||||||
|
@@ -9,6 +9,10 @@ namespace SqlSugar
|
|||||||
SqlSugarProvider Context { get; set; }
|
SqlSugarProvider Context { get; set; }
|
||||||
ICodeFirst BackupTable(int maxBackupDataRows = int.MaxValue);
|
ICodeFirst BackupTable(int maxBackupDataRows = int.MaxValue);
|
||||||
ICodeFirst SetStringDefaultLength(int length);
|
ICodeFirst SetStringDefaultLength(int length);
|
||||||
|
|
||||||
|
ICodeFirst As(Type type,string newTableName);
|
||||||
|
ICodeFirst As<T>(string newTableName);
|
||||||
|
|
||||||
void InitTables(string entitiesNamespace);
|
void InitTables(string entitiesNamespace);
|
||||||
void InitTables(string[] entitiesNamespaces);
|
void InitTables(string[] entitiesNamespaces);
|
||||||
void InitTables(params Type[] entityTypes);
|
void InitTables(params Type[] entityTypes);
|
||||||
|
Reference in New Issue
Block a user