This expression only includes data whose value for the filtered column is an empty string, and not a null string. This is a problem as we are trying to filter data whose value for this column is null.
Changes applied
In order to fixed this problem, I had to edit DefaultColumnFilter and TextFilterType files to change the way IsNull filters on text column are generated.
Changes on TextFilterType
In this class I added the GetNullOrEmptyCheck(Expression paramExpr) method which returns an expression calling string.IsNullOrEmpty on the filtered column. When querying the database, EF will translate this expression to this sql condition:
WHERE ([o].[ShipRegion] IS NULL) OR ([o].[ShipRegion] LIKE N'')
Including both data whose value for the filtered column is a null string or an empty string.
I then called this method in GetFilterExpression's switch, instead of GetCaseInsensitiveСomparation.
switch (filterType)
{
case GridFilterType.Equals:
binaryExpression = GetCaseInsensitiveСomparation(string.Empty, leftExpr, valueExpr, removeDiacritics);
break;
case GridFilterType.IsNull:
binaryExpression = GetNullOrEmptyCheck(leftExpr);
break;
Changes on DefaultColumnFilter
I then changed the way GetExpression was called in the case of an IsNull filter on a string column (line 124), so that it only returns the expression generated by the GetNullOrEmptyCheck method, and not an expression of the type :
Content of the PR This pr is a proposed solution for the bug explained in issue #381.
Explanation of the fixed bug
There was a problem in the way IsNull filters for text columns were generated by the
DefaultColumnFilter
class.For example, when applying an "IsNull" filter on a column named "shipRegion", the expression generated for the filter was as follows :
This expression only includes data whose value for the filtered column is an empty string, and not a null string. This is a problem as we are trying to filter data whose value for this column is null.
Changes applied
In order to fixed this problem, I had to edit
DefaultColumnFilter
andTextFilterType
files to change the way IsNull filters on text column are generated.Changes on
TextFilterType
In this class I added the
GetNullOrEmptyCheck(Expression paramExpr)
method which returns an expression calling string.IsNullOrEmpty on the filtered column. When querying the database, EF will translate this expression to this sql condition:Including both data whose value for the filtered column is a null string or an empty string.
I then called this method in
GetFilterExpression
's switch, instead ofGetCaseInsensitiveСomparation
.Changes on
DefaultColumnFilter
I then changed the way
GetExpression
was called in the case of an IsNull filter on a string column (line 124), so that it only returns the expression generated by theGetNullOrEmptyCheck
method, and not an expression of the type :Which would not make sense.