Let\'s say we have four entities in data model: Categories, Books, Authors and BookPages. Also assume Categories-Books, Books-Authors and Books-BookPages relationships are o
Some of the performance considerations are ADO.Net connector specific. I would keep in mind a database view or stored procedure as a backup if you're not getting the performance needed.
First, note that DbContext (and ObjectContext) objects are not thread-safe.
If you are concerned about clairity over performance, then the first option is the simplest.
On the other hand, if you're worried about performance--and are willing to dispose of the context object after getting the data--then you can query the data with multiple simultaneous tasks (threads) each using their own context object.
If you need a context to track changes to the data, you have the straight forward way of a single query to add all the items to the context, or you can use the Attach method to 'rebuild' the original state, and then change and save.
The latter goes something like:
using(var dbContext = new DbContext())
{
var categoryToChange = new Categories()
{
// set properties to original data
};
dbContext.Categories.Attach(categoryToChange);
// set changed properties
dbContext.SaveChanges();
}
Unfortunately there's no one best practice to meet all situations.