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. 15
      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, FieldName = item,
ConditionalType = ConditionalType.Equal, ConditionalType = ConditionalType.Equal,
FieldValue = model[item].ObjToString(), FieldValue = model[item]==null?"null" : model[item].ObjToString(),
CSharpTypeName = model[item] == null ? null : model[item].GetType().Name CSharpTypeName = model[item] == null ? null : model[item].GetType().Name
})); }));
i++; i++;

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

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

Loading…
Cancel
Save