0

On random occasions, users of our application are receiving this invalid cast exception The expected type was 'System.Int64' but the actual value was of type 'System.String'. This is not reproducible by us and it occurs on an identity (DataGrid.Id) field of our DataGrid model. The type in the database is bigint and the type in our model is long.

enter image description here

enter image description here

This seems to have started to occur after we started using ToListAsync instead of ToList on the entity.

public async Task<IEnumerable<TEntity>> GetAllAsync()
{
    return await _entitySet.ToListAsync();
}

I am not sure what is going on with these random requests throwing errors. I can provide a full stack trace if necessary, but the stack trace leads me to that line where it's throwing the exception, and it appears the data types match. This is usually a very random error and occurs once or twice every couple days. Can anyone suggest what may be occurring here?

Bohms27
  • 407
  • 1
  • 5
  • 16
  • 1
    Does this answer your question? [Use int Id for a bigint column in EF6](https://stackoverflow.com/questions/32266917/use-int-id-for-a-bigint-column-in-ef6) – Mathias R. Jessen Aug 05 '21 at 12:13
  • It might help, but I have no idea how to guarantee that it works since we can't reproduce. – Bohms27 Aug 10 '21 at 14:01

0 Answers0