Any reason not to use nested EF object contexts?

using (var context = new FirstEntities()) { using (var context1 = new SecondEntities()) { } } 

This works, but for some reason it doesnโ€™t โ€œfeel goodโ€ ... Does anyone know any reasonable reasons not to use nested expressions with the entity?

Edit: my question is more line by line, if there is a scenario in which this type of nesting can cause an exception or a database error, and not if it is appropriate from an architectural point of view ...

+7
source share
1 answer

Nested data contexts you will use two database connections at once. He prefers to get the data you need from one context, close it and open it further, and get the data you need from this context.

This may mean a bit more work, since you need to plan your code better, but it also means that the application scales better.

+11
source

All Articles