I am trying to dynamically generate linqtosql query using LinqKit. I would like to check the field that I want to add for the prediction before sending the expression to LinqKit. So I have come up with some idea like
Expression<Func<TResult, bool>> GetPrediction<TKey>
(Expression<Func<TResult, TKey>> selector, TResult input, object value)
{
if(typeof(TKey) == typeof(string))
{
return selector.Invoke(input) == value; //Not working, how to covert here?
}
Throw new Exception("Type not supported");
}
I am stuck at line 5, where I am supposed to generate an Expression<Func<TResult, bool>> and return. I know it’s possible but just have hard time to get the “click”
I think you want something like:
I’m not quite sure what kind of equality that will use, mind you – it’s entirely possible it’s going to use a reference equality operation, whereas I suspect you want value equality. You’ll have to try it to see, being careful in tests due to string interning.