Browse Source

pgsql Deleteable<T>().Where(class) Multiple primary key bugs

pull/8/head
sunkaixuna 3 years ago
parent
commit
05cd2a3c5c
  1. 21
      Src/Asp.Net/PgSqlTest/UnitTest/Updateable.cs
  2. 4
      Src/Asp.Net/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs
  3. 29
      Src/Asp.Net/SqlSugar/Realization/PostgreSQL/SqlBuilder/PostgreSQLExpressionContext.cs

21
Src/Asp.Net/PgSqlTest/UnitTest/Updateable.cs

@ -70,9 +70,28 @@ namespace OrmTest
.Where(it => it.a)
.ExecuteCommand();
// Db.CodeFirst.InitTables<UnitPk00121>();
//Db.CodeFirst.InitTables<UnitPk001212>();
//Db.Deleteable<UnitPk00121>().Where(new UnitPk00121() { Id=1, CreateTime=DateTime.Now, Name="a" }).ExecuteCommand();
//Db.Deleteable<UnitPk001212>().Where(new List<UnitPk001212> { new UnitPk001212() { Id = 1, CreateTime = DateTime.Now, Name = "a" } , new UnitPk001212() { Id = 2, CreateTime = DateTime.Now, Name = "11a" } }).ExecuteCommand();
}
}
public class UnitPk00121
{
[SugarColumn(IsPrimaryKey = true)]
public int Id { get; set; }
[SugarColumn(IsPrimaryKey = true)]
public DateTime? CreateTime { get; set; }
public string Name { get; set; }
}
public class UnitPk001212
{
[SugarColumn(IsPrimaryKey = true)]
public int Id { get; set; }
public DateTime? CreateTime { get; set; }
[SugarColumn(IsPrimaryKey = true)]
public string Name { get; set; }
}
public class BoolTest1
{
public bool a { get; set; }

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

@ -144,6 +144,10 @@ namespace SqlSugar
{
andString.AppendFormat(DeleteBuilder.WhereInEqualTemplate, primaryField.ToUpper(), entityValue);
}
else if (this.Context.CurrentConnectionConfig.DbType == DbType.PostgreSQL&& (this.Context.CurrentConnectionConfig.MoreSettings==null||this.Context.CurrentConnectionConfig.MoreSettings?.PgSqlIsAutoToLower==true))
{
andString.AppendFormat("\"{0}\"={1} ", primaryField.ToLower(), new PostgreSQLExpressionContext().GetValue(entityValue));
}
else
{
andString.AppendFormat(DeleteBuilder.WhereInEqualTemplate, primaryField, entityValue);

29
Src/Asp.Net/SqlSugar/Realization/PostgreSQL/SqlBuilder/PostgreSQLExpressionContext.cs

@ -101,6 +101,35 @@ namespace SqlSugar
return propertyName.ToLower(isAutoToLower);
}
}
public string GetValue(object entityValue)
{
if (entityValue == null)
return null;
var type = UtilMethods.GetUnderType(entityValue.GetType());
if (UtilConstants.NumericalTypes.Contains(type))
{
return entityValue.ToString();
}
else if (type == UtilConstants.DateType)
{
return this.DbMehtods.ToDate(new MethodCallExpressionModel()
{
Args = new System.Collections.Generic.List<MethodCallExpressionArgs>() {
new MethodCallExpressionArgs(){ MemberName=$"'{entityValue}'" }
}
});
}
else
{
return this.DbMehtods.ToString(new MethodCallExpressionModel()
{
Args = new System.Collections.Generic.List<MethodCallExpressionArgs>() {
new MethodCallExpressionArgs(){ MemberName=$"'{entityValue}'" }
}
});
}
}
}
public class PostgreSQLMethod : DefaultDbMethod, IDbMethods
{

Loading…
Cancel
Save