What is the best way to know whether my code first entity is from direct code (new DataObject())
or from context (Context.DataObjects.First())
Since i am not preventing my context from using dynamicproxies, i can do that :
protected DataObject()
{
if (this.GetType().Namespace != "System.Data.Entity.DynamicProxies")
{
this.Id = IdGenerator.NextId<DataObject>();
}
}
but this look like a bad solution, since GetType() is expensive.
Thank you
If you want to check the type of the entity you must call
GetType. Btw. there is recommended solution directly on MSDN. To get ObjectContext instance from DbContext you can use: