using (var context = new FirstEntities())
{
using (var context1 = new SecondEntities())
{
}
}
This works but for some reason doesn't "feel right"... Does anyone know any valid reason not to use nested using statements with entity framework?
Edit: My question is more along the lines if there is a scenario where this type of nesting could cause an exception or a database error rather than if it is advisable from architectural stand point...
By nesting data contexts you will use two database connections at once. It's preferrable to get the data that you need from one context, close that and open the next, and get the data that you need from that context.
This might mean a little more work as you have to plan your code better, but it also means that the application scales better.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With