In both EF Core and EF6, invoking the getter of the property 'Date' (see below) gives the correct value, however notice the slight difference between the two : in EF Core the setter is never called!
This is my model :
public class MyModel
{
private DateTime _Date;
private bool dateTimeHasBeenSet = false;
public DateTime Date
{
get
{
return _Date;
}
set
{
dateTimeHasBeenSet = true;
_Date = value;
}
}
}
This is my way to retrieve a single item :
//Entity Framework 6
using (Ef6Context context = new Ef6Context())
{
var m = context.MyModels.First();
// m.dateTimeHasBeenSet is true
}
//Entity Framework Core
using (EfCoreContext context = new EfCoreContext())
{
var m = context.MyModels.First();
// m.dateTimeHasBeenSet is false
}
Does EF core initialize the backup field instead of the property (through reflection)? doesn't this violate encapsulation?
I'm migrating some code from EF6 to EF Core and I really would like to avoid wasting time in manually invoking the logic behind each setter...
EDIT : Asking the question made me try something fancy, if I rename my backup field from _Property to any thing else like _PropertyX (In this example it would be _DateX) magically my setter is invoked by EF Core!