1
var a = _context.A.Include(e => e.R)
    .Where(e => e.Name.Contains("name"))
    .Skip(0)
    .Take(150)
    .ToList();

Error is pointing to this line. I don't use bytes. Someone can find error cause?

demo
  • 6,038
  • 19
  • 75
  • 149
Etana
  • 19
  • 5
  • my guess is that whatever model `A` is, there is a mismatch on one of the columns, where it is `tinyint` (or equivalent) in the database, but `int` in the model, and the ORM is failing when trying to blindly cast a `byte` value to an `int` member; in which case: fix the mapping? perhaps tell the model that the type is `byte`, not `int` ? but: we can't see `A` or the mapping, so I can only guess – Marc Gravell Oct 20 '21 at 11:52
  • R table have tinyint in database but int in model. How do i hange it to int? – Etana Oct 20 '21 at 11:59
  • Or this is imposible and i need model with byte and then cast to model with int? – Etana Oct 20 '21 at 12:12
  • 2
    I don't know if it is impossible or possible, but I'm a pragmatist: it seems like changing the member type would be the simplest way to fix the problem. Beyond that, you'd need to read the docs on whatever ORM you're using, and in particular the docs on member mapping and transformation. There may be a way to get that to happen automatically, but since you haven't even told us what ORM you're using here, I couldn't possibly guess. – Marc Gravell Oct 20 '21 at 12:14

1 Answers1

3

You have mismatched data types in your Model. The table R or A has a column with type byte, and you have defined your entity model with int.

In case if you need to have different types and behavior in the application, it is better to have the Entity Model separate from the Model definition in your project.

You could use automapping libraries such as https://github.com/AutoMapper/AutoMapper that help you convert easier between models.

By the way, this link below could help you to find more what is the difference between Entity and Model.

https://stackoverflow.com/a/39425005/993369

Omid Mafakher
  • 1,389
  • 1
  • 16
  • 40