Exception about disposing DbContext
This exception I've been getting is so confusing since every other source I tried looking up for solutions doesn't exactly apply to my code. So, the exception I'm getting is that my db context gets disposed before I can use another operation on the db. Everywhere Ive checked for help had people screwing up asynchronous operations, which isnt the case for me. Here is my file for reference
Am using pooled db context btw
5 Replies
Why aren't you using di for the context?
Did you add a bad finalizer to your context?
Does 'Guild' have any EF relation properties? You are putting the 'Guild' entry into a memory cache that outlives the DbContext it came from. If you try to access a relation property, it will try to use the disposed context to query the related entity and then throw an error like this.
Assuming lazy loading is enabled
my bad for late reply, but
Guild
isnt an EF object no
however, GuildModel
is
this is actually how GuildModel
is defined in another file
edit: optimized it a bitWhy do your models have constructors also not sure how EF could populate that ID prop, as it's get-only
Making the model dependent on IConfiguration is also quite smelly