You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello. I am having doubts when using DbContextFactory. Is there any difference between CreateDbContext() and new DbContext()?
Is there any difference between using DbContextFactory and using(=new DbContext())? Thank you, can you tell me?
The text was updated successfully, but these errors were encountered:
shouhujishu
changed the title
Hello, I can’t understand DbContextFactory. Can you simply answer it for me?
I am having doubts while learning DbContextFactory?
Jan 13, 2021
shouhujishu
changed the title
I am having doubts while learning DbContextFactory?
I am having doubts while learning DbContextFactory
Jan 13, 2021
@shouhujishu I don't know if you are still learning EF Core, but after spending a good amount of time, it seems there is really no best solution.
If you create a new instance each time, sure, you might escape concurrency problems, but you lose other properties of EF Core, like Caching.
And then if you want to span a DB transaction across multiple services, how do you do that? I am not an expert myself, but I would say you CAN'T. You'd have to pass around your original context and chose a point where you'd want to commit your transaction, or roll it back if you have any errors.
Each approach has pros and cons, so you'd have to make the choice yourself. I don't think there's any bad approach (putting aside using the same DbContext within multiple threads).
Hello. I am having doubts when using DbContextFactory. Is there any difference between CreateDbContext() and new DbContext()?
Is there any difference between using DbContextFactory and using(=new DbContext())? Thank you, can you tell me?
The text was updated successfully, but these errors were encountered: