Browse Source

Delete Join Sql Bug

pull/12/MERGE
sunkaixuan 8 years ago
parent
commit
20deae1124
  1. 2
      Src/Asp.Net/SqlServerTest/Program.cs
  2. 5
      Src/Asp.Net/SqlServerTest/UnitTest/Delete.cs
  3. 9
      Src/Asp.Net/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs
  4. 2
      Src/Asp.Net/SqlSugar/Interface/IDeleteable.cs
  5. 16
      Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs
  6. 2
      Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Interface/IDeleteable.cs

2
Src/Asp.Net/SqlServerTest/Program.cs

@ -26,7 +26,7 @@ namespace OrmTest
// new SelectQuery(1).Init();
// new AutoClose(1).Init();
// new Insert(1).Init();
// new Delete(1).Init();
new Delete(1).Init();
// new Update(1).Init();
// new Mapping(1).Init();
// new DataTest(1).Init();

5
Src/Asp.Net/SqlServerTest/UnitTest/Delete.cs

@ -51,6 +51,11 @@ namespace OrmTest
base.Check(@"DELETE FROM [STudent] WHERE ( [ID] = @Id0 ) ", new List<SugarParameter>() {
new SugarParameter("@Id0",1)
}, t5.Key, t5.Value, "Delte t5 error");
var t6 = db.Deleteable<Student>().Where("id=@id",new { id=1}).ToSql();
base.Check(@"DELETE FROM [STudent] WHERE id=@id", new List<SugarParameter>() {
new SugarParameter("@id",1)
}, t6.Key, t6.Value, "Delte t6 error");
}
public SqlSugarClient GetInstance()

9
Src/Asp.Net/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs

@ -109,12 +109,15 @@ namespace SqlSugar
return this;
}
public IDeleteable<T> Where(string whereString, object whereObj = null)
public IDeleteable<T> Where(string whereString, object parameters = null)
{
DeleteBuilder.WhereInfos.Add(whereString);
if (whereObj != null)
if (parameters != null)
{
DeleteBuilder.Parameters.AddRange(Context.Ado.GetParameters(whereObj));
if (DeleteBuilder.Parameters == null) {
DeleteBuilder.Parameters = new List<SugarParameter>();
}
DeleteBuilder.Parameters.AddRange(Context.Ado.GetParameters(parameters));
}
return this;
}

2
Src/Asp.Net/SqlSugar/Interface/IDeleteable.cs

@ -18,7 +18,7 @@ namespace SqlSugar
IDeleteable<T> In<PkType>(PkType primaryKeyValue);
IDeleteable<T> In<PkType>(PkType[] primaryKeyValues);
IDeleteable<T> In<PkType>(List<PkType> primaryKeyValues);
IDeleteable<T> Where(string whereString,object whereObj=null);
IDeleteable<T> Where(string whereString,object parameters=null);
KeyValuePair<string, List<SugarParameter>> ToSql();
}
}

16
Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs

@ -26,7 +26,7 @@ namespace SqlSugar
{
DeleteBuilder.EntityInfo = this.Context.EntityProvider.GetEntityInfo<T>();
string sql = DeleteBuilder.ToSqlString();
var paramters = DeleteBuilder.Parameters==null?null:DeleteBuilder.Parameters.ToArray();
var paramters = DeleteBuilder.Parameters == null ? null : DeleteBuilder.Parameters.ToArray();
RestoreMapping();
return Db.ExecuteCommand(sql, paramters);
}
@ -63,7 +63,7 @@ namespace SqlSugar
primaryKeyValues.Add(value);
}
var inValueString = primaryKeyValues.ToArray().ToJoinSqlInVals();
Where(string.Format(DeleteBuilder.WhereInTemplate,SqlBuilder.GetTranslationColumnName(primaryFields.Single()), inValueString));
Where(string.Format(DeleteBuilder.WhereInTemplate, SqlBuilder.GetTranslationColumnName(primaryFields.Single()), inValueString));
}
else
{
@ -109,12 +109,16 @@ namespace SqlSugar
return this;
}
public IDeleteable<T> Where(string whereString, object whereObj = null)
public IDeleteable<T> Where(string whereString, object parameters = null)
{
DeleteBuilder.WhereInfos.Add(whereString);
if (whereObj != null)
if (parameters != null)
{
DeleteBuilder.Parameters.AddRange(Context.Ado.GetParameters(whereObj));
if (DeleteBuilder.Parameters == null)
{
DeleteBuilder.Parameters = new List<SugarParameter>();
}
DeleteBuilder.Parameters.AddRange(Context.Ado.GetParameters(parameters));
}
return this;
}
@ -140,7 +144,7 @@ namespace SqlSugar
string primaryField = null;
primaryField = GetPrimaryKeys().FirstOrDefault();
Check.ArgumentNullException(primaryField, "Table " + tableName + " with no primarykey");
Where(string.Format(DeleteBuilder.WhereInTemplate,SqlBuilder.GetTranslationColumnName(primaryField), primaryKeyValues.ToJoinSqlInVals()));
Where(string.Format(DeleteBuilder.WhereInTemplate, SqlBuilder.GetTranslationColumnName(primaryField), primaryKeyValues.ToJoinSqlInVals()));
return this;
}

2
Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Interface/IDeleteable.cs

@ -18,7 +18,7 @@ namespace SqlSugar
IDeleteable<T> In<PkType>(PkType primaryKeyValue);
IDeleteable<T> In<PkType>(PkType[] primaryKeyValues);
IDeleteable<T> In<PkType>(List<PkType> primaryKeyValues);
IDeleteable<T> Where(string whereString,object whereObj=null);
IDeleteable<T> Where(string whereString, object parameters = null);
KeyValuePair<string, List<SugarParameter>> ToSql();
}
}

Loading…
Cancel
Save