Issue 186 and Issue 823

Topics: EF Runtime
Mar 11 at 8:06 PM
Hi, i have made a fix to resolve the issues 186 & 823.

Before submitting the pull request, i would like to discuss the detail of the implementation in this post.

The fix is divided in 2 parts, first part kicks in during CQT generation trying to remove redundant Convert, this is necessary since the .Net Framework generates an expression with unnecessary convert even when not needed, there is even a bug on connect, see here
https://connect.microsoft.com/VisualStudio/feedback/details/549615/remove-unnecessary-converts-from-expression-trees

This can be easily tested with following code (copy and paste in linqpad)
void Main()
{
    Expression<Func<Foo, bool>> expression = foo => foo.Bar == Bar.Value1;
    expression.Dump();
}

public class Foo
{
    public Bar Bar { get; set; }
}

public enum Bar : short
{
    Value1,
    Value2,
}
Although with the above fix EF removes the unnecessary cast introduced on the query with an equality filter, filter for inequality remain still broken (i.e. the cast is still present) because of how the SqlGenerator handles DbNotExpression,
so the second fix is to switch from VisitBinaryExpression to VisitComparisonExpression inside the Visit(DbNotExpression) to allow EF calculate correctly if the cast are really required.
Developer
Mar 12 at 4:56 PM
@iLMaX - this sounds promising. Can you submit a pull request with your changes?