Delete BUG with multiple primary keys

This commit is contained in:
sunkaixuan 2017-11-02 16:08:23 +08:00
parent 26abb4a0f5
commit 21f7027fb1
5 changed files with 26 additions and 4 deletions

View File

@ -56,6 +56,20 @@ namespace OrmTest
base.Check(@"DELETE FROM [STudent] WHERE id=@id", new List<SugarParameter>() {
new SugarParameter("@id",1)
}, t6.Key, t6.Value, "Delte t6 error");
var t7 = base.GetInstanceByAttribute().Deleteable<DeleteTestTable>().Where(new List<DeleteTestTable>() {
new DeleteTestTable() { Id=1, Id2="x" },
new DeleteTestTable() { Id=2, Id2="x1" }
}).ToSql();
base.Check("DELETE FROM [DeleteTestTable] WHERE (([Id]=N'1'AND [Id2]=N'x')OR ([Id]=N'2'AND [Id2]=N'x1')) ",null, t7.Key, null,
"Delte t7 error");
}
}
public class DeleteTestTable {
[SugarColumn(IsPrimaryKey =true)]
public int Id { get; set; }
[SugarColumn(IsPrimaryKey = true)]
public string Id2 { get; set; }
}
}

View File

@ -51,5 +51,11 @@ namespace OrmTest.UnitTest
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true });
return db;
}
public SqlSugarClient GetInstanceByAttribute()
{
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { InitKeyType=InitKeyType.Attribute, ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true });
return db;
}
}
}

View File

@ -74,7 +74,7 @@ namespace SqlSugar
string tableName = this.Context.EntityMaintenance.GetTableName<T>();
var primaryFields = this.GetPrimaryKeys();
var isSinglePrimaryKey = primaryFields.Count == 1;
Check.ArgumentNullException(primaryFields, string.Format("Table {0} with no primarykey", tableName));
Check.Exception(primaryFields.IsNullOrEmpty(), string.Format("Table {0} with no primarykey", tableName));
if (isSinglePrimaryKey)
{
List<object> primaryKeyValues = new List<object>();
@ -106,7 +106,7 @@ namespace SqlSugar
{
StringBuilder orString = new StringBuilder();
var isFirst = deleteObjs.IndexOf(deleteObj) == 0;
if (isFirst)
if (!isFirst)
{
orString.Append(DeleteBuilder.WhereInOrTemplate + UtilConstants.Space);
}
@ -114,7 +114,7 @@ namespace SqlSugar
StringBuilder andString = new StringBuilder();
foreach (var primaryField in primaryFields)
{
if (i == 0)
if (i != 0)
andString.Append(DeleteBuilder.WhereInAndTemplate + UtilConstants.Space);
var entityPropertyName = this.Context.EntityMaintenance.GetPropertyName<T>(primaryField);
var columnInfo = EntityInfo.Columns.Single(it => it.PropertyName == entityPropertyName);

View File

@ -65,7 +65,7 @@ namespace SqlSugar
{
get
{
return "[{0}]=N'{1}'";
return Builder.SqlTranslationLeft+"{0}"+Builder.SqlTranslationRight+"=N'{1}'";
}
}
public string WhereInAreaTemplate

View File

@ -12,6 +12,8 @@ namespace SqlSugar
CommandType CommandType { get; set; }
String AppendWhereOrAnd(bool isWhere, string sqlString);
string AppendHaving(string sqlString);
string SqlTranslationLeft { get; }
string SqlTranslationRight { get; }
SqlQueryBuilder SqlQueryBuilder { get; set; }
QueryBuilder QueryBuilder { get; set; }
InsertBuilder InsertBuilder { get; set; }