c# - LINQ Dynamic QUERY to produce 'where AssignedUser is null' -


i trying build dynamic expression query rows has null in column

where assigneduser null 

, below code, not doing expected. can 1 spread light on issue please?

private expression<func<vwassignmentactivities, bool>> getisnullexpressionequals<t>(string propname, t value) {     var item = expression.parameter(typeof(vwassignmentactivities), "item");     var prop = expression.convert(expression.property(item, propname), value.gettype());      expression body = expression.equal(prop, expression.constant(null, prop.type));      return expression.lambda<func<vwassignmentactivities, bool>>(body, item); } 

any appreciated

the error getting because have value in nullable. type returns int32 though variable nullable. trying convert null int.

assuming care finding null values, this

public type getnullable(type type) {     if (type == typeof(nullable<>))         return  type.gettype();      if(type == typeof(int))         type = typeof(int?);     else if(type == typeof(bool))         type = typeof(bool?);     else if(type == typeof(float))         type = typeof(float?);           // etc.  have build out every type want.      return type; }  public expression<func<vwassignmentactivities, bool>> getisnullexpressionequals(string propname, type value) {            var item = expression.parameter(typeof(vwassignmentactivities), "item");     var prop = expression.convert(expression.property(item, propname), getnullable(value));      expression body = expression.equal(prop, expression.constant(null, prop.type));      return expression.lambda<func<vwassignmentactivities, bool>>(body, item); } 

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -