I have an Expression
DateTime date = DateTime.Now;
Expression<Func<MyClass, bool>> exp = null;
my goal should be something like this
exp = x => x.Year > date.Year
but unfortunately MyClass.Year field is a string and I need to parse it. I have problems with Convert.ToInt32(x.Year) at the time EF converts the value to sql. How can I translate int.Parse operation into a correct sql statement with EF? Is there a way to do something like this?
exp = x =>
{
int val = int.Parse(x.Year);
return val > date.Year
}
There is a work around to do it just to compile it properly, but still looking for the other way, EF can't translate those call into sql:
private bool GetExpression(MyClass myClass, DateTime endDate)
{
int year = 0;
var res = int.TryParse(myClass.Year, out year);
if (res)
return year > endDate.Year;
return false;
}
exp = x => GetExpression(x, DateTime.Now)