I have a DbContext
with ProxyCreationEnabled
set to true (actually it's the default value).
As far as I remember, this enables EF to load proxy entities from database, so any change we make to properties are recognized by the change tracker, and we can call SaveChanges()
like this:
using (var db = new MyDbContext())
{
var people = db.People.Where(p => p.Status = PersonStatus.New).ToList();
foreach (var person in people)
{
person.Name = "Something";
}
db.SaveChanges();
}
The problem is: why would EF not use the proxy for a specific class, even though ProxyCreationEnabled
is true? The class is not sealed, so it should be able to use proxy.
Here is my sample class:
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
public DateTime RegisterDate { get; set; }
public PersonStatus Status { get; set; }
}