Supposed I have an entity framework entity named Foo, and in Foo a property called Bar.
Is there a way in the setter of Bar to get to the entity framework context?
public partial class Foo : IObjectWithChangeTracker
{
public string Bar
{
get { /* ... */ }
set
{
// How do I get the entity context here?
}
}
}
If I understand your question correctly my approach for doing this would be to add properties to
Barthat are not under the data contract then write another method that retrieves the other object and setBarsproperties there. But I may not understand your question for the reasons HighCore stated. The whole idea doesn’t make sense to me; an object does not own a context.If you’re searching by primary key you just remove the
FirstOrDefault(). If you can get back multiple results create another loop where you iterate overotherObj(potentially a list now) and filter on the next identifying property. After that loop you can just do normal assignment like