imagine I got an entity:
MyEntity
{
...
Nullable<Int64> MyProperty
...
}
I would like to do something like this:
Ctx.MyEntity.Where(x=>x.MyProperty/16 == 10)
with Linq.Expression
So I create a parameter:
var param = Expression.parameter(typeOf(MyEntity));
Then the property:
var prop = Expression.PropertyOrField(param,"MyProperty");
If I would like to compare to 10 I would have done something like this:
var cmp = Expression.equal(prop,Expression.constant(10,prop.Type));
But first I need to divide prop by 16.
So I try:
var div = Expression.Divide(prop,Expression.constant(16, prop.type);
And this throw an exception of unmatching type.
Can someone help ?
Thx,
You need to create division expression like this:
It is necessary to explicitly convert 16 to type of the property, since when used as a literal, it is of type
Int32, which is obviously not same asNullable<Int64>.