Update .net core project

This commit is contained in:
sunkaixuan
2022-07-04 08:03:10 +08:00
parent 2017771513
commit 62da5521b7
10 changed files with 137 additions and 36 deletions

View File

@@ -85,6 +85,10 @@ namespace SqlSugar
{ {
InitTables(typeof(T), typeof(T2), typeof(T3), typeof(T4)); 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) public virtual void InitTables(params Type[] entityTypes)
{ {
if (entityTypes.HasValue()) if (entityTypes.HasValue())

View File

@@ -263,6 +263,15 @@ namespace SqlSugar
TruncateTable<T4>(); TruncateTable<T4>();
return true; 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) public virtual bool DropColumn(string tableName, string columnName)
{ {
columnName = this.SqlBuilder.GetTranslationColumnName(columnName); columnName = this.SqlBuilder.GetTranslationColumnName(columnName);

View File

@@ -15,12 +15,27 @@ namespace SqlSugar
public DeleteNavProvider<Root,TChild> ThenInclude<TChild>(Expression<Func<T,TChild>> expression) public DeleteNavProvider<Root,TChild> ThenInclude<TChild>(Expression<Func<T,TChild>> expression)
{ {
return null; throw new Exception("开发中7月15号之前上线");
} }
public DeleteNavProvider<Root, TChild> Include<TChild>(Expression<Func<T, TChild>> expression)
public DeleteNavProvider<Root,Root> AsNav()
{ {
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;
} }
} }
} }

View File

@@ -67,7 +67,7 @@ namespace SqlSugar
var pkColumn = entity.Columns.FirstOrDefault(it => it.IsPrimarykey == true); var pkColumn = entity.Columns.FirstOrDefault(it => it.IsPrimarykey == true);
if (nav.Navigat.Name2.HasValue()) 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; return pkColumn;
} }
@@ -76,42 +76,66 @@ namespace SqlSugar
var fkColumn = entity.Columns.FirstOrDefault(it => it.PropertyName == nav.Navigat.Name); var fkColumn = entity.Columns.FirstOrDefault(it => it.PropertyName == nav.Navigat.Name);
return fkColumn; 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(); children = children.Distinct().ToList();
var x = this._Context.Storageable(children).WhereColumns(new string[] { pkColumn.PropertyName }).ToStorage(); var x = this._Context.Storageable(children).WhereColumns(new string[] { pkColumn.PropertyName }).ToStorage();
var insertData = children = x.InsertList.Select(it => it.Item).ToList(); 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); InsertIdentity(insertData);
} }
else if (pkColumn.UnderType==UtilConstants.LongType&&pkColumn.IsIdentity==false) else if (pkColumn.UnderType == UtilConstants.LongType)
{ {
foreach (var child in insertData) SetValue(pkColumn, insertData, ()=>SnowFlakeSingle.Instance.NextId());
{
if (IsDefaultValue(pkColumn.PropertyInfo.GetValue(child)))
{
pkColumn.PropertyInfo.SetValue(child, SnowFlakeSingle.Instance.NextId());
}
}
this._Context.Insertable(insertData).ExecuteCommand();
} }
else if (pkColumn.UnderType == UtilConstants.GuidType && pkColumn.IsIdentity == false) else if (pkColumn.UnderType == UtilConstants.GuidType)
{ {
foreach (var child in insertData) SetValue(pkColumn, insertData, () => Guid.NewGuid());
{ }
if (IsDefaultValue(pkColumn.PropertyInfo.GetValue(child))) else if (pkColumn.UnderType == UtilConstants.StringType)
{ {
pkColumn.PropertyInfo.SetValue(child, Guid.NewGuid()); SetValue(pkColumn, insertData, () => Guid.NewGuid().ToString());
} }
} else if (pkColumn.UnderType == UtilConstants.IntType)
this._Context.Insertable(insertData).ExecuteCommand(); {
SetError(pkColumn, insertData);
} }
else 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();
} }
} }
} }

View File

@@ -19,6 +19,11 @@ namespace SqlSugar
var thisPkColumn = GetPkColumnByNav(thisEntity, nav); var thisPkColumn = GetPkColumnByNav(thisEntity, nav);
var thisFkColumn= GetFKColumnByNav(thisEntity, nav); var thisFkColumn= GetFKColumnByNav(thisEntity, nav);
EntityColumnInfo parentPkColumn = GetParentPkColumn(); EntityColumnInfo parentPkColumn = GetParentPkColumn();
EntityColumnInfo parentNavColumn = GetParentPkNavColumn(nav);
if (parentNavColumn != null)
{
parentPkColumn = parentNavColumn;
}
foreach (var item in parentList) foreach (var item in parentList)
{ {
var parentValue = parentPkColumn.PropertyInfo.GetValue(item); var parentValue = parentPkColumn.PropertyInfo.GetValue(item);
@@ -45,6 +50,15 @@ namespace SqlSugar
} }
return parentPkColumn; 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() private void SetNewParent<TChild>(EntityInfo entityInfo,EntityColumnInfo entityColumnInfo) where TChild : class, new()
{ {

View File

@@ -31,6 +31,14 @@ namespace SqlSugar
{ {
navPropertyValue = pkValue; 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)) if (IsDefaultValue(navPropertyValue))
{ {

View File

@@ -13,7 +13,7 @@ namespace SqlSugar
public SqlSugarProvider Context { get; set; } public SqlSugarProvider Context { get; set; }
public InsertNavProvider<Root, Root> insertNavProvider { 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; this.Context = insertNavProvider._Context;
InsertNavTask<Root, TChild> result = new InsertNavTask<Root, TChild>(); InsertNavTask<Root, TChild> result = new InsertNavTask<Root, TChild>();
@@ -22,7 +22,7 @@ namespace SqlSugar
result.Context = this.Context; result.Context = this.Context;
return result; 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; this.Context = insertNavProvider._Context;
InsertNavTask<Root, TChild> result = new InsertNavTask<Root, TChild>(); InsertNavTask<Root, TChild> result = new InsertNavTask<Root, TChild>();
@@ -52,7 +52,15 @@ namespace SqlSugar
result.Context = this.Context; result.Context = this.Context;
return result; 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; var hasTran = this.Context.Ado.Transaction != null;
if (hasTran) if (hasTran)
@@ -66,17 +74,19 @@ namespace SqlSugar
PreFunc(); PreFunc();
}, ex => throw ex); }, ex => throw ex);
} }
return true;
} }
public async Task ExecuteCommandAsync() public async Task<bool> ExecuteCommandAsync()
{ {
await Task.Run(async () => await Task.Run(async () =>
{ {
ExecuteCommand(); ExecuteCommand();
await Task.Delay(0); await Task.Delay(0);
}); });
return true;
} }
public InsertNavTask<Root, Root> AsNav() private InsertNavTask<Root, Root> AsNav()
{ {
InsertNavTask<Root, Root> result = new InsertNavTask<Root, Root>(); InsertNavTask<Root, Root> result = new InsertNavTask<Root, Root>();
Func<InsertNavProvider<Root, Root>> func = () => PreFunc().AsNav(); Func<InsertNavProvider<Root, Root>> func = () => PreFunc().AsNav();

View File

@@ -15,10 +15,25 @@ namespace SqlSugar
public UpdateNavProvider<Root,TChild> ThenInclude<TChild>(Expression<Func<T,TChild>> expression) public UpdateNavProvider<Root,TChild> ThenInclude<TChild>(Expression<Func<T,TChild>> expression)
{ {
return null; throw new Exception("开发中7月15号之前上线");
} }
public UpdateNavProvider<Root, TChild> Include<TChild>(Expression<Func<T, TChild>> expression)
public UpdateNavProvider<Root,Root> AsNav() {
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; return null;
} }

View File

@@ -17,6 +17,7 @@ namespace SqlSugar
void InitTables<T, T2>(); void InitTables<T, T2>();
void InitTables<T, T2, T3>(); void InitTables<T, T2, T3>();
void InitTables<T, T2, T3, T4>(); void InitTables<T, T2, T3, T4>();
void InitTables<T, T2, T3, T4,T5>();
SplitCodeFirstProvider SplitTables(); SplitCodeFirstProvider SplitTables();
TableDifferenceProvider GetDifferenceTables<T>(); TableDifferenceProvider GetDifferenceTables<T>();
TableDifferenceProvider GetDifferenceTables(params Type[] types); TableDifferenceProvider GetDifferenceTables(params Type[] types);

View File

@@ -36,6 +36,7 @@ namespace SqlSugar
bool TruncateTable<T,T2>(); bool TruncateTable<T,T2>();
bool TruncateTable<T, T2, T3>(); bool TruncateTable<T, T2, T3>();
bool TruncateTable<T, T2, T3,T4>(); bool TruncateTable<T, T2, T3,T4>();
bool TruncateTable<T, T2, T3, T4,T5>();
bool CreateTable(string tableName, List<DbColumnInfo> columns,bool isCreatePrimaryKey=true); bool CreateTable(string tableName, List<DbColumnInfo> columns,bool isCreatePrimaryKey=true);
bool AddColumn(string tableName, DbColumnInfo column); bool AddColumn(string tableName, DbColumnInfo column);
bool UpdateColumn(string tableName, DbColumnInfo column); bool UpdateColumn(string tableName, DbColumnInfo column);