【发布时间】:2023-03-18 13:42:01
【问题描述】:
有什么方法可以查看实体的关系是如何在 ChangeInterceptor() 中受到影响/改变的?这是使用 NorthWind 数据库的示例,当您从关系是一对多的员工实体中删除/删除订单实体时,一个员工有许多订单,如何检测从员工实体中删除的订单。我知道使用 ObjectStateEntry 类,您可以调用 GetModifiedProperties() 来查看属性发生了哪些变化,但是我们如何查看集合/关联发生了什么变化?和RelationshipManager有关系吗?
[ChangeInterceptor("Employees"]
public void OnChangeEmployees(Employee employee, UpdateOperations operations)
{
//I'm using EntityFramework 4.1
//We have to dropdown the ObjectContext to detect IA, Independant Association, changes
ObjectContext ctx = ((IObjectContextAdapter)this.CurrentDataSource).ObjectContext;
ObjectStateEntry entry = ctx.ObjectStateManager.GetObjectStateEntry(employee);
//What do I do here for detecting relationship changes.. I.E and Order was added?
}
提前致谢。
【问题讨论】:
标签: wcf entity-framework entity-framework-4 entity-framework-4.1