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

This commit is contained in:
sunkaixuna 2021-09-09 18:20:06 +08:00
parent 3b523d5d55
commit 05cd2a3c5c
3 changed files with 53 additions and 1 deletions

View File

@ -70,9 +70,28 @@ namespace OrmTest
.Where(it => it.a) .Where(it => it.a)
.ExecuteCommand(); .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 class BoolTest1
{ {
public bool a { get; set; } public bool a { get; set; }

View File

@ -144,6 +144,10 @@ namespace SqlSugar
{ {
andString.AppendFormat(DeleteBuilder.WhereInEqualTemplate, primaryField.ToUpper(), entityValue); 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 else
{ {
andString.AppendFormat(DeleteBuilder.WhereInEqualTemplate, primaryField, entityValue); andString.AppendFormat(DeleteBuilder.WhereInEqualTemplate, primaryField, entityValue);

View File

@ -101,6 +101,35 @@ namespace SqlSugar
return propertyName.ToLower(isAutoToLower); 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 public class PostgreSQLMethod : DefaultDbMethod, IDbMethods
{ {