locked
Byte in LINQ TO SQL question RRS feed

  • Question

  • I have a MSSQL table with a tinyint field.
    When I have a simple where clause in linq on a tinyint, the generated sql is casting this field to an int.

    The problem is that my indexes are not used anymore.

    For example:

    in sql: select * from SomeTable where TinyIntField = 1

    will generated by linq to the following

    select * from SomeTable where cast(TinyIntField as int) = 1

    How can I avoid this pittfall?

    Thanks

    Wednesday, May 28, 2014 5:43 AM

Answers

  • It is a wll know issue in EF: https://entityframework.codeplex.com/workitem/823 - workaround is to change the field to be int for now

    Please mark as answer, if this was it. Visit my SQL Server Compact blog http://erikej.blogspot.com

    • Proposed as answer by Fred Bao Thursday, May 29, 2014 3:09 AM
    • Marked as answer by Fred Bao Thursday, June 5, 2014 10:03 AM
    Wednesday, May 28, 2014 10:08 AM