mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-11-08 10:24:55 +08:00
Update core
This commit is contained in:
@@ -11,6 +11,7 @@ namespace SqlSugar
|
||||
{
|
||||
|
||||
public List<Root> Roots { get; set; }
|
||||
public SqlSugarProvider Context { get; internal set; }
|
||||
|
||||
public DeleteNavProvider<Root,TChild> ThenInclude<TChild>(Expression<Func<T,TChild>> expression)
|
||||
{
|
||||
|
||||
@@ -7,16 +7,78 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class InsertNavProvider<Root,T>
|
||||
public class InsertNavProvider<Root,T> where T : class,new() where Root:class,new()
|
||||
{
|
||||
|
||||
public List<Root> Roots { get; set; }
|
||||
public object ParentList { get; set; }
|
||||
public EntityInfo ParentEntity { get; set; }
|
||||
public SqlSugarProvider Context { get; set; }
|
||||
|
||||
public InsertNavProvider<Root,TChild> ThenInclude<TChild>(Expression<Func<T,TChild>> expression)
|
||||
public InsertNavProvider<Root,TChild> ThenInclude<TChild>(Expression<Func<T,TChild>> expression) where TChild : class, new()
|
||||
{
|
||||
if (ParentList == null)
|
||||
{
|
||||
ParentList = GetParentList(Roots);
|
||||
}
|
||||
var name=ExpressionTool.GetMemberName(expression);
|
||||
var nav = this.ParentEntity.Columns.FirstOrDefault(x => x.PropertyName == name);
|
||||
if (nav.Navigat == null)
|
||||
{
|
||||
Check.ExceptionEasy($"{name} no navigate attribute", $"{this.ParentEntity.EntityName}的属性{name}没有导航属性");
|
||||
}
|
||||
if (nav.Navigat.NavigatType == NavigateType.OneToOne || nav.Navigat.NavigatType == NavigateType.ManyToOne)
|
||||
{
|
||||
InsertOneToOne();
|
||||
}
|
||||
else if (nav.Navigat.NavigatType == NavigateType.OneToMany)
|
||||
{
|
||||
InsertOneToMany();
|
||||
}
|
||||
else
|
||||
{
|
||||
InsertManyToMany();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void InsertManyToMany()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void InsertOneToMany()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void InsertOneToOne()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private List<Type> GetParentList<Type>(List<Type> datas) where Type : class ,new()
|
||||
{
|
||||
List<Type> result = new List<Type>();
|
||||
this.Context.InitMappingInfo<Type>();
|
||||
var entity = this.Context.EntityMaintenance.GetEntityInfo<Type>();
|
||||
var isIdentity = entity.Columns.Where(it=>it.IsIdentity).Any();
|
||||
if (isIdentity)
|
||||
{
|
||||
foreach (var item in datas)
|
||||
{
|
||||
this.Context.Insertable(datas).ExecuteCommandIdentityIntoEntity();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Context.Insertable(datas).ExecuteCommand();
|
||||
}
|
||||
this.ParentEntity = entity;
|
||||
result = datas;
|
||||
return result;
|
||||
}
|
||||
|
||||
public InsertNavProvider<Root,Root> AsNav()
|
||||
{
|
||||
return null;
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace SqlSugar
|
||||
{
|
||||
|
||||
public List<Root> Roots { get; set; }
|
||||
public SqlSugarProvider Context { get; internal set; }
|
||||
|
||||
public UpdateNavProvider<Root,TChild> ThenInclude<TChild>(Expression<Func<T,TChild>> expression)
|
||||
{
|
||||
|
||||
@@ -295,7 +295,7 @@ namespace SqlSugar
|
||||
this.Context.InitMappingInfo(navEntityInfo.Type);
|
||||
var navPkColumn = navEntityInfo.Columns.Where(it => it.IsPrimarykey).FirstOrDefault();
|
||||
Check.ExceptionEasy(navPkColumn==null&& navObjectNameColumnInfo.Navigat.Name2==null, navEntityInfo.EntityName+ "need primarykey", navEntityInfo.EntityName + " 需要主键");
|
||||
if (navPkColumn==null)
|
||||
if (navObjectNameColumnInfo.Navigat.Name2.HasValue())
|
||||
{
|
||||
navPkColumn = navEntityInfo.Columns.Where(it => it.PropertyName== navObjectNameColumnInfo.Navigat.Name2).FirstOrDefault();
|
||||
}
|
||||
@@ -341,7 +341,7 @@ namespace SqlSugar
|
||||
//var navType = navObjectNamePropety.PropertyType;
|
||||
var listItemPkColumn = listItemEntity.Columns.Where(it => it.IsPrimarykey).FirstOrDefault();
|
||||
Check.ExceptionEasy(listItemPkColumn == null&& navObjectNameColumnInfo.Navigat.Name2==null, listItemEntity.EntityName + " not primary key", listItemEntity.EntityName + "没有主键");
|
||||
if (listItemPkColumn == null)
|
||||
if (navObjectNameColumnInfo.Navigat.Name2.HasValue())
|
||||
{
|
||||
listItemPkColumn = listItemEntity.Columns.Where(it => it.PropertyName== navObjectNameColumnInfo.Navigat.Name2).FirstOrDefault();
|
||||
}
|
||||
|
||||
@@ -890,14 +890,15 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Nav CUD
|
||||
public InsertNavProvider<T, T> InsertNav<T>(T data)
|
||||
public InsertNavProvider<T, T> InsertNav<T>(T data) where T : class, new()
|
||||
{
|
||||
return InsertNav(new List<T>() { data });
|
||||
}
|
||||
public InsertNavProvider<T, T> InsertNav<T>(List<T> datas)
|
||||
public InsertNavProvider<T, T> InsertNav<T>(List<T> datas) where T : class, new()
|
||||
{
|
||||
var result = new InsertNavProvider<T, T>();
|
||||
result.Roots = datas;
|
||||
result.Context = this;
|
||||
return result;
|
||||
}
|
||||
public DeleteNavProvider<T, T> DeleteNav<T>(T data)
|
||||
@@ -908,6 +909,7 @@ namespace SqlSugar
|
||||
{
|
||||
var result = new DeleteNavProvider<T, T>();
|
||||
result.Roots = datas;
|
||||
result.Context = this;
|
||||
return result;
|
||||
}
|
||||
public UpdateNavProvider<T, T> UpdateNav<T>(T data)
|
||||
@@ -918,6 +920,7 @@ namespace SqlSugar
|
||||
{
|
||||
var result = new UpdateNavProvider<T, T>();
|
||||
result.Roots = datas;
|
||||
result.Context = this;
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -678,11 +678,11 @@ namespace SqlSugar
|
||||
{
|
||||
return ScopedContext.Saveable(saveObject);
|
||||
}
|
||||
public InsertNavProvider<T, T> InsertNav<T>(T data)
|
||||
public InsertNavProvider<T, T> InsertNav<T>(T data) where T : class, new()
|
||||
{
|
||||
return ScopedContext.InsertNav(data);
|
||||
}
|
||||
public InsertNavProvider<T, T> InsertNav<T>(List<T> datas)
|
||||
public InsertNavProvider<T, T> InsertNav<T>(List<T> datas) where T : class, new()
|
||||
{
|
||||
return ScopedContext.InsertNav(datas);
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ namespace SqlSugar
|
||||
private MapperSql GetOneToManySql()
|
||||
{
|
||||
var pkColumn = this.EntityInfo.Columns.FirstOrDefault(it => it.IsPrimarykey == true);
|
||||
if (pkColumn == null && Navigat.Name2 != null)
|
||||
if (Navigat.Name2.HasValue())
|
||||
{
|
||||
pkColumn = this.EntityInfo.Columns.FirstOrDefault(it => it.PropertyName== Navigat.Name2);
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace SqlSugar
|
||||
" NavigateType.Dynamic 自定义导航对象不支持在Where(x=>x.自定义.Id==1)等方法中使用"+ this.ProPertyEntity.Type.Name);
|
||||
}
|
||||
var pk = this.ProPertyEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true)?.DbColumnName;
|
||||
if (pk == null && Navigat.Name2 != null)
|
||||
if (Navigat.Name2.HasValue())
|
||||
{
|
||||
pk = this.ProPertyEntity.Columns.FirstOrDefault(it => it.PropertyName == Navigat.Name2)?.DbColumnName;
|
||||
}
|
||||
|
||||
@@ -203,8 +203,8 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Nav CUD
|
||||
InsertNavProvider<T, T> InsertNav<T>(T data);
|
||||
InsertNavProvider<T, T> InsertNav<T>(List<T> datas);
|
||||
InsertNavProvider<T, T> InsertNav<T>(T data) where T : class, new();
|
||||
InsertNavProvider<T, T> InsertNav<T>(List<T> datas) where T : class, new();
|
||||
DeleteNavProvider<T, T> DeleteNav<T>(T data);
|
||||
DeleteNavProvider<T, T> DeleteNav<T>(List<T> datas);
|
||||
UpdateNavProvider<T, T> UpdateNav<T>(T data);
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace SqlSugar
|
||||
IInsertable<T> InsertableWithAttr<T>(T insertObj) where T : class, new();
|
||||
IInsertable<T> InsertableWithAttr<T>(List<T> insertObjs) where T : class, new();
|
||||
IUpdateable<T> UpdateableWithAttr<T>(T updateObj) where T : class, new();
|
||||
IUpdateable<T> UpdateableWithAttr<T>() where T : class, new();
|
||||
IUpdateable<T> UpdateableWithAttr<T>(List<T> updateObjs) where T : class, new();
|
||||
IDeleteable<T> DeleteableWithAttr<T>(T deleteObjs) where T : class, new();
|
||||
IDeleteable<T> DeleteableWithAttr<T>(List<T> deleteObjs) where T : class, new();
|
||||
|
||||
@@ -154,11 +154,11 @@ namespace SqlSugar
|
||||
#region Queryable
|
||||
|
||||
#region Nav CUD
|
||||
public InsertNavProvider<T, T> InsertNav<T>(T data)
|
||||
public InsertNavProvider<T, T> InsertNav<T>(T data) where T : class, new()
|
||||
{
|
||||
return this.Context.InsertNav(data);
|
||||
}
|
||||
public InsertNavProvider<T, T> InsertNav<T>(List<T> datas)
|
||||
public InsertNavProvider<T, T> InsertNav<T>(List<T> datas) where T : class, new()
|
||||
{
|
||||
return this.Context.InsertNav(datas);
|
||||
}
|
||||
@@ -1288,6 +1288,10 @@ namespace SqlSugar
|
||||
{
|
||||
return this.GetConnectionWithAttr<T>().Updateable(updateObj);
|
||||
}
|
||||
public IUpdateable<T> UpdateableWithAttr<T>() where T : class, new()
|
||||
{
|
||||
return this.GetConnectionWithAttr<T>().Updateable<T>();
|
||||
}
|
||||
public IUpdateable<T> UpdateableWithAttr<T>(List<T> updateObjs) where T : class, new()
|
||||
{
|
||||
return this.GetConnectionWithAttr<T>().Updateable(updateObjs);
|
||||
|
||||
@@ -711,6 +711,12 @@ namespace SqlSugar
|
||||
{
|
||||
return ScopedContext.UpdateableWithAttr<T>(updateObj);
|
||||
}
|
||||
|
||||
public IUpdateable<T> UpdateableWithAttr<T>() where T : class, new()
|
||||
{
|
||||
return ScopedContext.UpdateableWithAttr<T>();
|
||||
}
|
||||
|
||||
public IUpdateable<T> UpdateableWithAttr<T>(List<T> updateObjs) where T : class, new()
|
||||
{
|
||||
return ScopedContext.UpdateableWithAttr<T>(updateObjs);
|
||||
@@ -724,11 +730,11 @@ namespace SqlSugar
|
||||
return ScopedContext.DeleteableWithAttr<T>(deleteObjs);
|
||||
}
|
||||
|
||||
public InsertNavProvider<T, T> InsertNav<T>(T data)
|
||||
public InsertNavProvider<T, T> InsertNav<T>(T data) where T : class, new()
|
||||
{
|
||||
return ScopedContext.InsertNav(data);
|
||||
}
|
||||
public InsertNavProvider<T, T> InsertNav<T>(List<T> datas)
|
||||
public InsertNavProvider<T, T> InsertNav<T>(List<T> datas) where T : class, new()
|
||||
{
|
||||
return ScopedContext.InsertNav(datas);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user