Browse Source

Where(conditionals)

pull/20/head
sunkaixuan 2 years ago
parent
commit
eac1e1709d
  1. 2
      Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs
  2. 11
      Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider.cs

2
Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs

@ -432,7 +432,7 @@ namespace SqlSugar
{
FieldName = item,
ConditionalType = ConditionalType.Equal,
FieldValue = model[item].ObjToString(),
FieldValue = model[item]==null?"null" : model[item].ObjToString(),
CSharpTypeName = model[item] == null ? null : model[item].GetType().Name
}));
i++;

11
Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider.cs

@ -164,8 +164,19 @@ namespace SqlSugar
switch (item.ConditionalType)
{
case ConditionalType.Equal:
if (item.FieldValue!=null&&item.FieldValue == "null"&&item.FieldValue!= "[null]")
{
builder.AppendFormat($" {item.FieldName.ToSqlFilter()} is null ");
}
else
{
if (item.FieldValue == "[null]")
{
item.FieldValue = "null";
}
builder.AppendFormat(temp, type, item.FieldName.ToSqlFilter(), "=", parameterName);
parameters.Add(new SugarParameter(parameterName, GetFieldValue(item)));
}
break;
case ConditionalType.Like:
builder.AppendFormat(temp, type, item.FieldName.ToSqlFilter(), "LIKE", parameterName);

Loading…
Cancel
Save