I’m running a net8.0 aspnet server using entity framework. One table in my database is for “Users”, but it contains 2 different types via a discriminator “Buyer” and “Seller”. In the code, Buyer and Seller are both subclasses of User
In the app, I specify a type of user using linq like this
Buyer buyer = context.Users
.OfType<Buyer>()
.Where(x => x.Id == userGuid)
.FirstOrDefault()
this works fine, except when I try and do the exact same thing from my xunit testing project.
when I do, I get a InvalidCastException Unable to cast object of type 'App.Data.User' to type 'App.Data.Buyer'.