views:

109

answers:

1

Hi!

I'm using Entity Framework. Registering the handler for the SavingChanges event, for the further processing deleted entities.


public partial class MyModel
{
  partial void OnContextCreated()
  {
    this.SavingChanges += new EventHandler(onSavingChanges);
  }

  private void onSavingChanges(object sender, EventArgs e)
  {
    ObjectStateManager context = ((ObjectContext)sender).ObjectStateManager;
    var Entities = context.GetObjectStateEntries(EntityState.Deleted).Where(x => !x.IsRelationship);

    foreach (ObjectStateEntry entry in Entities)
    {
        vo_pull currPull = entry.Entity as vo_pull 
        currPull.v_warehouse_sections // reference is null

    //tried another way
    Guid id = (entry.Entity as vo_pull).id;
    vo_pull currPull = ((ObjectContext)sender as CargoLogixEntities).vo_pull.Include("v_warehouse_sections").Where(x => x.id == id).FirstOrDefault(); //tried this way, references (v_warehouse_sections) are still null
    currPull.v_warehouse_sections //still null                    
     }  

  }
}

In Entities I've filtered deleted entities. When I'm choosing the entity object from Entities, and cast it into some entity Type, everything is ok, except the references (navigation properties), that are null's.

What I'm doing wrong?

Thanks