public static void AddOrAttachLink(this DataServiceContext context, object source, string propertyName, object target) { var descriptor = context.GetLinkDescriptor(source, propertyName, target); if (descriptor == null) { context.AddLink(source, propertyName, target); } else if (descriptor.State == EntityStates.Deleted) { context.DetachLink(source, propertyName, target); context.AttachLink(source, propertyName, target); } }