When working with the Entity Framework, you can do with a single database context, or you can distribute models over several. All work goes within one DB, Code First is used.

When and why use multiple contexts? Does it make sense to use different contexts when working with one database?

  • If your base is like in the picture , I think it will be good to use several contexts. - Ruslan_K

1 answer 1

It all depends on the size of your subject area. Sometimes it is convenient to split the domain into several independent small contexts within a single database, this will make it possible to very easily divide the database into several using the boundaries of the context. You can also create several partially overlapping contexts with identical entity names but with a different set of fields. Within the context of one context, operations with all entities included in it can be performed in a single transaction. In order to understand whether you need to divide the database into contexts, read about the Bounded Context, for example at Habré ( https://habrahabr.ru/post/232881/ )