SmallInt and TinyInt issue in Entity Framework

There is a problem in Entity Framework discussed here and here the problem is that when you filter table by int16 or int8 column, generated query will not use and index :

class MyEntity
{
    public short Id { get; set; }
}
class MyContext : DbContext
{
    public DbSet<MyEntity> MyEntities { get; set; }
}
class Program
{
    static void Main(string[] args)
    {
    using (var db = new MyContext())
        {
    short i = 8;
            Console.WriteLine(db.MyEntities.Where(e => e.Id == i).ToString());
            Console.ReadKey();
        }
    }
}
Output of the program will be

    SELECT
    [Extent1].[Id] AS [Id]
    FROM [dbo].[MyEntities] AS [Extent1]
    WHERE  CAST( [Extent1].[Id] AS int) = @p__linq__0
Notice that Id is compared after CAST is applied, and if you have an index by Id, it will not be used. The issue belongs rather to language team, because them put casts in expression tree during compilation.

Possible solutions

Expression rewrite solution

using System;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
class MyEntity
{
    public short Id { get; set; }
}
class MyContext : DbContext
{
    public DbSet<MyEntity> MyEntities { get; set; }
}
public class FixIntCastVisitor : ExpressionVisitor
{
    public override Expression Visit(Expression node)
    {
    return base.Visit(node);
    }
    protected override Expression VisitBinary(BinaryExpression node)
    {
    if (node.NodeType == ExpressionType.Equal)
        {
    var leftUnary = node.Left as UnaryExpression;
    var rightUnary = node.Right as UnaryExpression;
    if (rightUnary != null && 
                leftUnary != null && 
                leftUnary.NodeType == ExpressionType.Convert &&
                rightUnary.NodeType == ExpressionType.Convert &&
                leftUnary.Type == typeof(int) &&
                rightUnary.Type == typeof(int) &&
                (leftUnary.Operand.Type == typeof(short) || leftUnary.Operand.Type == typeof(byte)) &&
                (leftUnary.Operand.Type == rightUnary.Operand.Type)
                )
            {
    return Expression.Equal(leftUnary.Operand, rightUnary.Operand);
            }
    return base.VisitBinary(node);
        }
    return base.VisitBinary(node);
    }
}
static class IntCastFix
{
    public static IQueryable<T> FixIntCast<T>(this IQueryable<T> q)
    {
    var visitor = new FixIntCastVisitor();
        Expression original = q.Expression;
    var expr = visitor.Visit(original);
    return q.Provider.CreateQuery<T>(expr);
    }
}
class Program
{
    static void Main(string[] args)
    {
    using (var db = new MyContext())
        {
    short i = 8;
            Console.WriteLine(db.MyEntities.Where(e => e.Id == i).FixIntCast().ToString());
            Console.ReadKey();
        }
    }
}
And result is clean for SQL to use index:

    SELECT
    [Extent1].[Id] AS [Id]
    FROM [dbo].[MyEntities] AS [Extent1]
    WHERE [Extent1].[Id] = @p__linq__0