mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-18 17:48:11 +08:00
Saveable BUG
This commit is contained in:
@@ -96,6 +96,14 @@ namespace OrmTest.BugTest
|
|||||||
DB.CodeFirst.InitTables(typeof(DataTest));
|
DB.CodeFirst.InitTables(typeof(DataTest));
|
||||||
DB.Insertable(new DataTest()).ExecuteCommand();
|
DB.Insertable(new DataTest()).ExecuteCommand();
|
||||||
|
|
||||||
|
// 初始化实体表
|
||||||
|
DB.CodeFirst.SetStringDefaultLength(255).InitTables(typeof(TestA));
|
||||||
|
|
||||||
|
var testa = new TestA();
|
||||||
|
testa.Col1 = "2333333";
|
||||||
|
testa.Col3 = "444";
|
||||||
|
|
||||||
|
DB.Saveable(testa).ExecuteCommand();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,7 +122,24 @@ namespace OrmTest.BugTest
|
|||||||
|
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
}
|
}
|
||||||
|
public class Base : ModelContext
|
||||||
|
{
|
||||||
|
|
||||||
|
[SugarColumn(IsPrimaryKey = true)]
|
||||||
|
public string Id { get; set; } = Guid.NewGuid().ToString();
|
||||||
|
|
||||||
|
|
||||||
|
[SugarColumn(IsNullable = true)]
|
||||||
|
public string Col3 { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TestA : Base
|
||||||
|
{
|
||||||
|
public string Col1 { get; set; }
|
||||||
|
|
||||||
|
[SugarColumn(IsIgnore = true)]
|
||||||
|
public string Col2 { get; set; }
|
||||||
|
}
|
||||||
public partial class UserOrganizationUnit
|
public partial class UserOrganizationUnit
|
||||||
{
|
{
|
||||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||||
|
@@ -34,7 +34,7 @@ namespace SqlSugar
|
|||||||
var pks = GetPrimaryKeys();
|
var pks = GetPrimaryKeys();
|
||||||
Check.Exception(pks.IsNullOrEmpty(), "Need primary key");
|
Check.Exception(pks.IsNullOrEmpty(), "Need primary key");
|
||||||
Check.Exception(pks.Count() > 1, "Multiple primary keys are not supported");
|
Check.Exception(pks.Count() > 1, "Multiple primary keys are not supported");
|
||||||
var pkInfo = this.EntityInfo.Columns.Where(it => it.DbColumnName.Equals(pks.First(), StringComparison.CurrentCultureIgnoreCase)).First();
|
var pkInfo = this.EntityInfo.Columns.Where(it=>it.IsIgnore==false).Where(it => it.DbColumnName.Equals(pks.First(), StringComparison.CurrentCultureIgnoreCase)).First();
|
||||||
var pkValues = saveObjects.Select(it=>it.GetType().GetProperty(pkInfo.PropertyName).GetValue(it,null));
|
var pkValues = saveObjects.Select(it=>it.GetType().GetProperty(pkInfo.PropertyName).GetValue(it,null));
|
||||||
if(existsObjects==null)
|
if(existsObjects==null)
|
||||||
existsObjects=this.Context.Queryable<T>().In(pkValues).ToList();
|
existsObjects=this.Context.Queryable<T>().In(pkValues).ToList();
|
||||||
@@ -56,7 +56,7 @@ namespace SqlSugar
|
|||||||
var pks = GetPrimaryKeys();
|
var pks = GetPrimaryKeys();
|
||||||
Check.Exception(pks.IsNullOrEmpty(), "Need primary key");
|
Check.Exception(pks.IsNullOrEmpty(), "Need primary key");
|
||||||
Check.Exception(pks.Count() > 1, "Multiple primary keys are not supported");
|
Check.Exception(pks.Count() > 1, "Multiple primary keys are not supported");
|
||||||
var pkInfo = this.EntityInfo.Columns.Where(it => it.DbColumnName.Equals(pks.First(), StringComparison.CurrentCultureIgnoreCase)).First();
|
var pkInfo = this.EntityInfo.Columns.Where(it => it.IsIgnore == false).Where(it => it.DbColumnName.Equals(pks.First(), StringComparison.CurrentCultureIgnoreCase)).First();
|
||||||
var pkValues = saveObjects.Select(it => it.GetType().GetProperty(pkInfo.PropertyName).GetValue(it, null));
|
var pkValues = saveObjects.Select(it => it.GetType().GetProperty(pkInfo.PropertyName).GetValue(it, null));
|
||||||
if (existsObjects == null)
|
if (existsObjects == null)
|
||||||
existsObjects = this.Context.Queryable<T>().In(pkValues).ToList();
|
existsObjects = this.Context.Queryable<T>().In(pkValues).ToList();
|
||||||
|
Reference in New Issue
Block a user