mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-10-27 03:09:34 +08:00
Synchronization code
This commit is contained in:
@@ -213,11 +213,19 @@ namespace SqlSugar
|
|||||||
var bEntity = navObjectNameColumnInfo.PropertyInfo.PropertyType.GetGenericArguments()[0];
|
var bEntity = navObjectNameColumnInfo.PropertyInfo.PropertyType.GetGenericArguments()[0];
|
||||||
var bEntityInfo = this.Context.EntityMaintenance.GetEntityInfo(bEntity);
|
var bEntityInfo = this.Context.EntityMaintenance.GetEntityInfo(bEntity);
|
||||||
var bPkColumn = bEntityInfo.Columns.FirstOrDefault(it => it.IsPrimarykey);
|
var bPkColumn = bEntityInfo.Columns.FirstOrDefault(it => it.IsPrimarykey);
|
||||||
|
if (bPkColumn == null && navObjectNameColumnInfo.Navigat.BClassId.HasValue())
|
||||||
|
{
|
||||||
|
bPkColumn= bEntityInfo.Columns.FirstOrDefault(it => it.PropertyName == navObjectNameColumnInfo.Navigat.BClassId);
|
||||||
|
}
|
||||||
Check.ExceptionEasy(bPkColumn==null, $"{bEntityInfo.EntityName} need primary key", $"{bEntityInfo.EntityName} 实体需要配置主键");
|
Check.ExceptionEasy(bPkColumn==null, $"{bEntityInfo.EntityName} need primary key", $"{bEntityInfo.EntityName} 实体需要配置主键");
|
||||||
var bDb = this.Context;
|
var bDb = this.Context;
|
||||||
bDb = GetCrossDatabase(bDb,bEntity);
|
bDb = GetCrossDatabase(bDb,bEntity);
|
||||||
bDb.InitMappingInfo(bEntity);
|
bDb.InitMappingInfo(bEntity);
|
||||||
var listItemPkColumn = listItemEntity.Columns.Where(it => it.IsPrimarykey).FirstOrDefault();
|
var listItemPkColumn = listItemEntity.Columns.Where(it => it.IsPrimarykey).FirstOrDefault();
|
||||||
|
if (listItemPkColumn == null && navObjectNameColumnInfo.Navigat.AClassId.HasValue())
|
||||||
|
{
|
||||||
|
listItemPkColumn = listItemEntity.Columns.FirstOrDefault(it => it.PropertyName == navObjectNameColumnInfo.Navigat.AClassId);
|
||||||
|
}
|
||||||
Check.ExceptionEasy(listItemPkColumn == null, $"{listItemEntity.EntityName} need primary key", $"{listItemEntity.EntityName} 实体需要配置主键");
|
Check.ExceptionEasy(listItemPkColumn == null, $"{listItemEntity.EntityName} need primary key", $"{listItemEntity.EntityName} 实体需要配置主键");
|
||||||
var ids = list.Select(it => it.GetType().GetProperty(listItemPkColumn.PropertyName).GetValue(it)).Select(it => it == null ? "null" : it).Distinct().ToList();
|
var ids = list.Select(it => it.GetType().GetProperty(listItemPkColumn.PropertyName).GetValue(it)).Select(it => it == null ? "null" : it).Distinct().ToList();
|
||||||
var mappingEntity = this.Context.EntityMaintenance.GetEntityInfo(navObjectNameColumnInfo.Navigat.MappingType);
|
var mappingEntity = this.Context.EntityMaintenance.GetEntityInfo(navObjectNameColumnInfo.Navigat.MappingType);
|
||||||
|
|||||||
@@ -239,8 +239,10 @@ namespace SqlSugar
|
|||||||
internal string MappingBId { get; set; }
|
internal string MappingBId { get; set; }
|
||||||
internal NavigateType NavigatType { get; set; }
|
internal NavigateType NavigatType { get; set; }
|
||||||
internal string WhereSql { get; set; }
|
internal string WhereSql { get; set; }
|
||||||
|
internal string AClassId { get; set; }
|
||||||
|
|
||||||
|
internal string BClassId { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public string GetName()
|
public string GetName()
|
||||||
{
|
{
|
||||||
return Name;
|
return Name;
|
||||||
@@ -291,13 +293,22 @@ namespace SqlSugar
|
|||||||
//Check.ExceptionEasy(navigatType != NavigateType.OneToOne, "Currently, only one-to-one navigation configuration Sql conditions are supported", "目前导航配置Sql条件只支持一对一");
|
//Check.ExceptionEasy(navigatType != NavigateType.OneToOne, "Currently, only one-to-one navigation configuration Sql conditions are supported", "目前导航配置Sql条件只支持一对一");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Navigate(Type MappingTableType,string typeAiD,string typeBId)
|
public Navigate(Type MappingTableType,string typeAId,string typeBId)
|
||||||
{
|
{
|
||||||
this.MappingType = MappingTableType;
|
this.MappingType = MappingTableType;
|
||||||
this.MappingAId = typeAiD;
|
this.MappingAId = typeAId;
|
||||||
this.MappingBId = typeBId;
|
this.MappingBId = typeBId;
|
||||||
this.NavigatType = NavigateType.ManyToMany;
|
this.NavigatType = NavigateType.ManyToMany;
|
||||||
}
|
}
|
||||||
|
public Navigate(Type MappingTableType, string mappingAId, string mappingBId,string aClassId,string bClassId)
|
||||||
|
{
|
||||||
|
this.MappingType = MappingTableType;
|
||||||
|
this.MappingAId = mappingAId;
|
||||||
|
this.MappingBId = mappingBId;
|
||||||
|
this.AClassId = aClassId;
|
||||||
|
this.BClassId = bClassId;
|
||||||
|
this.NavigatType = NavigateType.ManyToMany;
|
||||||
|
}
|
||||||
public Navigate(Type MappingTableType, string typeAiD, string typeBId,string mappingSql)
|
public Navigate(Type MappingTableType, string typeAiD, string typeBId,string mappingSql)
|
||||||
{
|
{
|
||||||
this.MappingType = MappingTableType;
|
this.MappingType = MappingTableType;
|
||||||
|
|||||||
@@ -211,6 +211,14 @@ namespace SqlSugar
|
|||||||
|
|
||||||
var bPk = this.ProPertyEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true)?.DbColumnName;
|
var bPk = this.ProPertyEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true)?.DbColumnName;
|
||||||
var aPk = this.EntityInfo.Columns.FirstOrDefault(it => it.IsPrimarykey == true)?.DbColumnName;
|
var aPk = this.EntityInfo.Columns.FirstOrDefault(it => it.IsPrimarykey == true)?.DbColumnName;
|
||||||
|
if (bPk == null)
|
||||||
|
{
|
||||||
|
bPk= this.ProPertyEntity.Columns.FirstOrDefault(it => it.PropertyName == Navigat.BClassId)?.DbColumnName;
|
||||||
|
}
|
||||||
|
if (aPk == null)
|
||||||
|
{
|
||||||
|
aPk = this.EntityInfo.Columns.FirstOrDefault(it => it.PropertyName == Navigat.AClassId)?.DbColumnName;
|
||||||
|
}
|
||||||
Check.ExceptionEasy(aPk.IsNullOrEmpty(), $"{this.EntityInfo.EntityName}need primary key", $"{this.EntityInfo.EntityName}需要主键");
|
Check.ExceptionEasy(aPk.IsNullOrEmpty(), $"{this.EntityInfo.EntityName}need primary key", $"{this.EntityInfo.EntityName}需要主键");
|
||||||
Check.ExceptionEasy(bPk.IsNullOrEmpty(), $"{this.ProPertyEntity.EntityName}need primary key", $"{this.ProPertyEntity.EntityName}需要主键");
|
Check.ExceptionEasy(bPk.IsNullOrEmpty(), $"{this.ProPertyEntity.EntityName}need primary key", $"{this.ProPertyEntity.EntityName}需要主键");
|
||||||
MapperSql mapper = new MapperSql();
|
MapperSql mapper = new MapperSql();
|
||||||
|
|||||||
Reference in New Issue
Block a user