Does that mean changes only to a specific record cannot happen?
Yes, this is true AFAIK. But you can create multiple DbContext
instances without any problem.
If the data in the database is changed (by another application), how does the context get up-to-date information?
The data is not loaded when the context is constructed but when it is requested:
using(var db = new MyDbContext())
{
var items = db.MyItems.Where(i => i.Something == true);
var list = items.ToList(); // <= here the DB is queried
}
items
will be a IQueryable<MyItem>
object and as long as you keep it a IQueryable
the DB is not actually queried. Meaning you can add additional Where
or OrderBy
without DB-access. As soon as you convert it to IEnumerable
(e.g. with the ToList
from my example) or execute some specific methods (like e.g. First
) the DB will be queried.