Saveable BUG

This commit is contained in:
sunkaixuan
2019-04-10 19:05:39 +08:00
parent fca972451e
commit 9a462981dd
2 changed files with 27 additions and 2 deletions

View File

@@ -96,6 +96,14 @@ namespace OrmTest.BugTest
DB.CodeFirst.InitTables(typeof(DataTest));
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 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
{
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]

View File

@@ -34,7 +34,7 @@ namespace SqlSugar
var pks = GetPrimaryKeys();
Check.Exception(pks.IsNullOrEmpty(), "Need primary key");
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));
if(existsObjects==null)
existsObjects=this.Context.Queryable<T>().In(pkValues).ToList();
@@ -56,7 +56,7 @@ namespace SqlSugar
var pks = GetPrimaryKeys();
Check.Exception(pks.IsNullOrEmpty(), "Need primary key");
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));
if (existsObjects == null)
existsObjects = this.Context.Queryable<T>().In(pkValues).ToList();