efcore icon indicating copy to clipboard operation
efcore copied to clipboard

InvalidCastException on wrong property type in entity

Open kamkie opened this issue 4 years ago • 4 comments

exception message when mapping is not compatible is not very detailed and don't even say what property was problematic one

---> System.AggregateException: One or more errors occurred. (Unable to cast object of type 'System.Byte' to type 'System.String'.)
---> System.InvalidCastException: Unable to cast object of type 'System.Byte' to type 'System.String'.

kamkie avatar Oct 14 '22 15:10 kamkie

@kamkie please post the full exception including the stack trace, as well as a minimal code sample which triggers this exception; there's not much we can do with an isolated exception message.

roji avatar Oct 14 '22 15:10 roji

it is not about bug that you need to reproduce and fix it is about error message you have column in database that is tinyint -> it should be byte in entity but I did mistake and put string there but I have 20 or 100 columns in that table/entity and I don't know which one is wrong

kamkie avatar Oct 14 '22 15:10 kamkie

@kamkie See https://learn.microsoft.com/en-us/ef/core/logging-events-diagnostics/extensions-logging?tabs=v3#detailed-query-exceptions. If that doesn't help, then please post more information as requested by @roji.

ajcvickers avatar Oct 19 '22 19:10 ajcvickers

optionsBuilder.EnableDetailedErrors(); solves my problem

kamkie avatar Oct 19 '22 19:10 kamkie