mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-11-08 02:14:53 +08:00
Update .net core project
This commit is contained in:
@@ -85,6 +85,10 @@ namespace SqlSugar
|
||||
{
|
||||
InitTables(typeof(T), typeof(T2), typeof(T3), typeof(T4));
|
||||
}
|
||||
public void InitTables<T, T2, T3, T4,T5>()
|
||||
{
|
||||
InitTables(typeof(T), typeof(T2), typeof(T3), typeof(T4),typeof(T5));
|
||||
}
|
||||
public virtual void InitTables(params Type[] entityTypes)
|
||||
{
|
||||
if (entityTypes.HasValue())
|
||||
|
||||
@@ -263,6 +263,15 @@ namespace SqlSugar
|
||||
TruncateTable<T4>();
|
||||
return true;
|
||||
}
|
||||
public virtual bool TruncateTable<T, T2, T3, T4,T5>()
|
||||
{
|
||||
TruncateTable<T>();
|
||||
TruncateTable<T2>();
|
||||
TruncateTable<T3>();
|
||||
TruncateTable<T4>();
|
||||
TruncateTable<T5>();
|
||||
return true;
|
||||
}
|
||||
public virtual bool DropColumn(string tableName, string columnName)
|
||||
{
|
||||
columnName = this.SqlBuilder.GetTranslationColumnName(columnName);
|
||||
|
||||
@@ -15,12 +15,27 @@ namespace SqlSugar
|
||||
|
||||
public DeleteNavProvider<Root,TChild> ThenInclude<TChild>(Expression<Func<T,TChild>> expression)
|
||||
{
|
||||
return null;
|
||||
throw new Exception("开发中7月15号之前上线");
|
||||
}
|
||||
|
||||
public DeleteNavProvider<Root,Root> AsNav()
|
||||
public DeleteNavProvider<Root, TChild> Include<TChild>(Expression<Func<T, TChild>> expression)
|
||||
{
|
||||
return null;
|
||||
throw new Exception("开发中7月15号之前上线");
|
||||
}
|
||||
public DeleteNavProvider<Root, TChild> ThenInclude<TChild>(Expression<Func<T, List<TChild>>> expression)
|
||||
{
|
||||
throw new Exception("开发中7月15号之前上线");
|
||||
}
|
||||
public DeleteNavProvider<Root, TChild> Include<TChild>(Expression<Func<T, List<TChild>>> expression)
|
||||
{
|
||||
throw new Exception("开发中7月15号之前上线");
|
||||
}
|
||||
private DeleteNavProvider<Root,Root> AsNav()
|
||||
{
|
||||
throw new Exception("开发中7月15号之前上线");
|
||||
}
|
||||
public bool ExecuteCommand()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace SqlSugar
|
||||
var pkColumn = entity.Columns.FirstOrDefault(it => it.IsPrimarykey == true);
|
||||
if (nav.Navigat.Name2.HasValue())
|
||||
{
|
||||
pkColumn = _ParentEntity.Columns.FirstOrDefault(it => it.PropertyName == nav.Navigat.Name2);
|
||||
pkColumn = entity.Columns.FirstOrDefault(it => it.PropertyName == nav.Navigat.Name2);
|
||||
}
|
||||
return pkColumn;
|
||||
}
|
||||
@@ -76,42 +76,66 @@ namespace SqlSugar
|
||||
var fkColumn = entity.Columns.FirstOrDefault(it => it.PropertyName == nav.Navigat.Name);
|
||||
return fkColumn;
|
||||
}
|
||||
private void InsertDatas<TChild>(List<TChild> children, EntityColumnInfo pkColumn) where TChild : class, new()
|
||||
private void InsertDatas<TChild>(List<TChild> children, EntityColumnInfo pkColumn, EntityColumnInfo NavColumn=null) where TChild : class, new()
|
||||
{
|
||||
children = children.Distinct().ToList();
|
||||
var x = this._Context.Storageable(children).WhereColumns(new string[] { pkColumn.PropertyName }).ToStorage();
|
||||
var insertData = children = x.InsertList.Select(it => it.Item).ToList();
|
||||
if (pkColumn.IsIdentity||pkColumn.OracleSequenceName.HasValue())
|
||||
Check.ExceptionEasy(pkColumn==null&&NavColumn==null,$"The entity is invalid",$"实体错误无法使用导航");
|
||||
InitData(pkColumn, insertData);
|
||||
this._ParentList = children.Cast<object>().ToList();
|
||||
}
|
||||
|
||||
private void InitData<TChild>(EntityColumnInfo pkColumn, List<TChild> insertData) where TChild : class, new()
|
||||
{
|
||||
if (pkColumn.IsIdentity || pkColumn.OracleSequenceName.HasValue())
|
||||
{
|
||||
InsertIdentity(insertData);
|
||||
}
|
||||
else if (pkColumn.UnderType==UtilConstants.LongType&&pkColumn.IsIdentity==false)
|
||||
else if (pkColumn.UnderType == UtilConstants.LongType)
|
||||
{
|
||||
foreach (var child in insertData)
|
||||
{
|
||||
if (IsDefaultValue(pkColumn.PropertyInfo.GetValue(child)))
|
||||
{
|
||||
pkColumn.PropertyInfo.SetValue(child, SnowFlakeSingle.Instance.NextId());
|
||||
}
|
||||
}
|
||||
this._Context.Insertable(insertData).ExecuteCommand();
|
||||
SetValue(pkColumn, insertData, ()=>SnowFlakeSingle.Instance.NextId());
|
||||
}
|
||||
else if (pkColumn.UnderType == UtilConstants.GuidType && pkColumn.IsIdentity == false)
|
||||
else if (pkColumn.UnderType == UtilConstants.GuidType)
|
||||
{
|
||||
foreach (var child in insertData)
|
||||
{
|
||||
if (IsDefaultValue(pkColumn.PropertyInfo.GetValue(child)))
|
||||
{
|
||||
pkColumn.PropertyInfo.SetValue(child, Guid.NewGuid());
|
||||
}
|
||||
}
|
||||
this._Context.Insertable(insertData).ExecuteCommand();
|
||||
SetValue(pkColumn, insertData, () => Guid.NewGuid());
|
||||
}
|
||||
else if (pkColumn.UnderType == UtilConstants.StringType)
|
||||
{
|
||||
SetValue(pkColumn, insertData, () => Guid.NewGuid().ToString());
|
||||
}
|
||||
else if (pkColumn.UnderType == UtilConstants.IntType)
|
||||
{
|
||||
SetError(pkColumn, insertData);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._Context.Insertable(insertData).ExecuteCommand();
|
||||
|
||||
}
|
||||
this._ParentList = children.Cast<object>().ToList();
|
||||
}
|
||||
|
||||
private void SetValue<TChild>(EntityColumnInfo pkColumn, List<TChild> insertData,Func<object> value) where TChild : class, new()
|
||||
{
|
||||
foreach (var child in insertData)
|
||||
{
|
||||
if (IsDefaultValue(pkColumn.PropertyInfo.GetValue(child)))
|
||||
{
|
||||
pkColumn.PropertyInfo.SetValue(child, value());
|
||||
}
|
||||
}
|
||||
this._Context.Insertable(insertData).ExecuteCommand();
|
||||
}
|
||||
private void SetError<TChild>(EntityColumnInfo pkColumn, List<TChild> insertData) where TChild : class, new()
|
||||
{
|
||||
foreach (var child in insertData)
|
||||
{
|
||||
if (IsDefaultValue(pkColumn.PropertyInfo.GetValue(child)))
|
||||
{
|
||||
var name = pkColumn.EntityName + " " + pkColumn.DbColumnName;
|
||||
Check.ExceptionEasy($"The field {name} is not an autoassignment type and requires an assignment", $"字段{name}不是可自动赋值类型,需要赋值");
|
||||
}
|
||||
}
|
||||
this._Context.Insertable(insertData).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,11 @@ namespace SqlSugar
|
||||
var thisPkColumn = GetPkColumnByNav(thisEntity, nav);
|
||||
var thisFkColumn= GetFKColumnByNav(thisEntity, nav);
|
||||
EntityColumnInfo parentPkColumn = GetParentPkColumn();
|
||||
EntityColumnInfo parentNavColumn = GetParentPkNavColumn(nav);
|
||||
if (parentNavColumn != null)
|
||||
{
|
||||
parentPkColumn = parentNavColumn;
|
||||
}
|
||||
foreach (var item in parentList)
|
||||
{
|
||||
var parentValue = parentPkColumn.PropertyInfo.GetValue(item);
|
||||
@@ -45,6 +50,15 @@ namespace SqlSugar
|
||||
}
|
||||
return parentPkColumn;
|
||||
}
|
||||
private EntityColumnInfo GetParentPkNavColumn(EntityColumnInfo nav)
|
||||
{
|
||||
EntityColumnInfo result = null;
|
||||
if (nav.Navigat.Name2.HasValue())
|
||||
{
|
||||
result = _ParentPkColumn = this._ParentEntity.Columns.FirstOrDefault(it => it.PropertyName== nav.Navigat.Name2);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void SetNewParent<TChild>(EntityInfo entityInfo,EntityColumnInfo entityColumnInfo) where TChild : class, new()
|
||||
{
|
||||
|
||||
@@ -31,6 +31,14 @@ namespace SqlSugar
|
||||
{
|
||||
navPropertyValue = pkValue;
|
||||
}
|
||||
|
||||
}
|
||||
if (!IsDefaultValue(navPropertyValue))
|
||||
{
|
||||
this._Context.Updateable<DbTableInfo>
|
||||
().AS(parentEntity.DbTableName)
|
||||
.SetColumns(parentColumn.DbColumnName, navPropertyValue)
|
||||
.Where(parentPkColumn.DbColumnName, "=", parentPkColumn.PropertyInfo.GetValue(parent)).ExecuteCommand();
|
||||
}
|
||||
if (IsDefaultValue(navPropertyValue))
|
||||
{
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace SqlSugar
|
||||
public SqlSugarProvider Context { get; set; }
|
||||
public InsertNavProvider<Root, Root> insertNavProvider { get; set; }
|
||||
|
||||
public InsertNavTask<Root, TChild> ThenInclude<TChild>(Expression<Func<Root, TChild>> expression) where TChild : class, new()
|
||||
public InsertNavTask<Root, TChild> Include<TChild>(Expression<Func<Root, TChild>> expression) where TChild : class, new()
|
||||
{
|
||||
this.Context = insertNavProvider._Context;
|
||||
InsertNavTask<Root, TChild> result = new InsertNavTask<Root, TChild>();
|
||||
@@ -22,7 +22,7 @@ namespace SqlSugar
|
||||
result.Context = this.Context;
|
||||
return result;
|
||||
}
|
||||
public InsertNavTask<Root, TChild> ThenInclude<TChild>(Expression<Func<Root, List<TChild>>> expression) where TChild : class, new()
|
||||
public InsertNavTask<Root, TChild> Include<TChild>(Expression<Func<Root, List<TChild>>> expression) where TChild : class, new()
|
||||
{
|
||||
this.Context = insertNavProvider._Context;
|
||||
InsertNavTask<Root, TChild> result = new InsertNavTask<Root, TChild>();
|
||||
@@ -52,7 +52,15 @@ namespace SqlSugar
|
||||
result.Context = this.Context;
|
||||
return result;
|
||||
}
|
||||
public void ExecuteCommand()
|
||||
public InsertNavTask<Root, TChild> Include<TChild>(Expression<Func<Root, TChild>> expression) where TChild : class, new()
|
||||
{
|
||||
return AsNav().ThenInclude(expression);
|
||||
}
|
||||
public InsertNavTask<Root, TChild> Include<TChild>(Expression<Func<Root, List<TChild>>> expression) where TChild : class, new()
|
||||
{
|
||||
return AsNav().ThenInclude(expression);
|
||||
}
|
||||
public bool ExecuteCommand()
|
||||
{
|
||||
var hasTran = this.Context.Ado.Transaction != null;
|
||||
if (hasTran)
|
||||
@@ -66,17 +74,19 @@ namespace SqlSugar
|
||||
PreFunc();
|
||||
}, ex => throw ex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public async Task ExecuteCommandAsync()
|
||||
public async Task<bool> ExecuteCommandAsync()
|
||||
{
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
ExecuteCommand();
|
||||
await Task.Delay(0);
|
||||
});
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
public InsertNavTask<Root, Root> AsNav()
|
||||
private InsertNavTask<Root, Root> AsNav()
|
||||
{
|
||||
InsertNavTask<Root, Root> result = new InsertNavTask<Root, Root>();
|
||||
Func<InsertNavProvider<Root, Root>> func = () => PreFunc().AsNav();
|
||||
|
||||
@@ -15,10 +15,25 @@ namespace SqlSugar
|
||||
|
||||
public UpdateNavProvider<Root,TChild> ThenInclude<TChild>(Expression<Func<T,TChild>> expression)
|
||||
{
|
||||
return null;
|
||||
throw new Exception("开发中7月15号之前上线");
|
||||
}
|
||||
|
||||
public UpdateNavProvider<Root,Root> AsNav()
|
||||
public UpdateNavProvider<Root, TChild> Include<TChild>(Expression<Func<T, TChild>> expression)
|
||||
{
|
||||
throw new Exception("开发中7月15号之前上线");
|
||||
}
|
||||
public UpdateNavProvider<Root, TChild> ThenInclude<TChild>(Expression<Func<T, List<TChild>>> expression)
|
||||
{
|
||||
throw new Exception("开发中7月15号之前上线");
|
||||
}
|
||||
public UpdateNavProvider<Root, TChild> Include<TChild>(Expression<Func<T, List<TChild>>> expression)
|
||||
{
|
||||
throw new Exception("开发中7月15号之前上线");
|
||||
}
|
||||
public bool ExecuteCommand()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
private UpdateNavProvider<Root,Root> AsNav()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace SqlSugar
|
||||
void InitTables<T, T2>();
|
||||
void InitTables<T, T2, T3>();
|
||||
void InitTables<T, T2, T3, T4>();
|
||||
void InitTables<T, T2, T3, T4,T5>();
|
||||
SplitCodeFirstProvider SplitTables();
|
||||
TableDifferenceProvider GetDifferenceTables<T>();
|
||||
TableDifferenceProvider GetDifferenceTables(params Type[] types);
|
||||
|
||||
@@ -36,6 +36,7 @@ namespace SqlSugar
|
||||
bool TruncateTable<T,T2>();
|
||||
bool TruncateTable<T, T2, T3>();
|
||||
bool TruncateTable<T, T2, T3,T4>();
|
||||
bool TruncateTable<T, T2, T3, T4,T5>();
|
||||
bool CreateTable(string tableName, List<DbColumnInfo> columns,bool isCreatePrimaryKey=true);
|
||||
bool AddColumn(string tableName, DbColumnInfo column);
|
||||
bool UpdateColumn(string tableName, DbColumnInfo column);
|
||||
|
||||
Reference in New Issue
Block a user