【问题标题】:Using ChangeInterceptor to inspect "Relationship" changes/mutations between entities使用 ChangeInterceptor 检查实体之间的“关系”更改/突变
【发布时间】: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


    【解决方案1】:

    而不是使用 ChangeInterceptor... 只需在 ObjectContext 上实现 SavingChanges 事件处理程序。这个article 解释了如何查看实体的关系是否受到影响。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-06
      • 2018-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多