C# Linq predicate generation remove all null values from list -
i trying generate filter code using linq predicates. when use predicate object != null:
public static expression<func<contactpermitssearch, bool>> permitnumbernotnull() { expression<func<contactpermitssearch, bool>> predicate = contactpermit => contactpermit.permitnumber != null; return predicate; }
which called by:
public static iqueryable<contactpermitssearch> filterbynamemailingpermit(this iqueryable<contactpermitssearch> queryable, string search, bool filteron) { var predicate = predicatebuilder.true<contactpermitssearch>(); predicate = predicate.and(permitnumbernotnull()); var filtered = queryable.asexpandable().where(predicate); return filtered; }
the sql statement generated not include permitnumbernotnull predicate statement.
thoughts on fixing this?
there's nothing wrong code. i'm sure if inspect predicate
in debugger after merging permitnumbernotnull()
you'll see not null predicate part of expression tree.
the reasonable assumption ef knows contactpermit.permitnumber
can't ever null because it's required property. therefore, ignores predicate.
Comments
Post a Comment