0

I am using SQLite in my application and my table is defined as per this EF model:

internal class Board
{
    public string BoardID { get; set; }
    public ushort BoardNumber { get; set; }
    public string Content { get; set; }

    public Board()
    {
        BoardID = string.Empty;
        Content = string.Empty;
        BoardNumber = 0;
    }
}

The property names match exactly the database columns. I am able to fetch records with the same model using LINQ to Entity. However, when I try this operation it fails with the error stated in the subject:

using (var db = new Models.EF.MyDbContext())
{
     int last - db.Boards.Max(n => n.BoardNumber);
}

The column in the database is named "BoardNumber" and is of type integer (SQLite) and is NOT the PK.

Why is this operation failing?

Lord of Scripts
  • 3,579
  • 5
  • 41
  • 62
  • See what query is generated using the profiler and then try executing the same query against the sqllite db directly and see if it works. – CodingYoshi Jan 16 '17 at 23:19
  • Don't yo have a typo there? the negative sign should be replaced with an assignment (=) sign, right? – Sparrow Jan 16 '17 at 23:20

1 Answers1

1

This is likely because your current type is a ushort and unsigned integers and types are not supported in LINQ to Entities.

You may want to consider using a different type if that is feasible, or consider implementing another approach for reading those specific values similar to the one mentioned here.

Community
  • 1
  • 1
Rion Williams
  • 74,820
  • 37
  • 200
  • 327