Richard BeierRichard Beier

My feedback

  1. 666 votes
    Vote
    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      You have left! (?) (thinking…)
      Richard BeierRichard Beier commented  · 

      I was able to work around this by putting the following in my OrderRepository, before the call to context.SaveChanges():

      var orphans = _context.ObjectStateManager.GetObjectStateEntries(EntityState.Modified)
      .Select(x => x.Entity)
      .OfType<OrderLine>()
      .Where(x => x.OrderID == null)
      .ToList();

      foreach ( var orphan in orphans )
      _context.DeleteObject(orphan);

      But I still think there should be an option for this in the mapping :).

      Thanks,
      Richard

      Richard BeierRichard Beier shared this idea  · 

    Feedback and Knowledge Base