locked
how to avoid creating a new entity and then trying to delete one of its links? RRS feed

  • Question

  • I have a situation where the user creates a new entity, one of the links in that entity is set with a combobox. The problem is that if the user tabs over the combobox without setting a value a null is set to the setter for that property (or consider the case where the user sets the value then resets it to null). The problem is this causes issues with WCF Data Services in as much as "In batch mode, a resource can be cross-referenced only for bind/unbind operations". This makes sense to me, setting this to null, would issue a delete and creating a new entity and then trying to delete one of its links is not supported. my question is how is one to deal with this?

    Wrapping the property and ignoring null values will not work because the user might rightfully want to null out a set value.

     

    Friday, May 20, 2011 8:13 PM

Answers

  • You can look at the state of the entity and ignore the null value if the entity is in added state. Here's the code which shows how to get the state of the entity. If the entity is not in added state, then, as you said, the user might be rightfully wanting to null the link (i.e. delete it)

    context.GetEntityDescriptor(object entity).State

    Hope this helps.

    Thanks

    Pratik


    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by GAX user Wednesday, May 25, 2011 9:22 PM
    Wednesday, May 25, 2011 9:19 PM
    Moderator

All replies

  • You can look at the state of the entity and ignore the null value if the entity is in added state. Here's the code which shows how to get the state of the entity. If the entity is not in added state, then, as you said, the user might be rightfully wanting to null the link (i.e. delete it)

    context.GetEntityDescriptor(object entity).State

    Hope this helps.

    Thanks

    Pratik


    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by GAX user Wednesday, May 25, 2011 9:22 PM
    Wednesday, May 25, 2011 9:19 PM
    Moderator
  • Thanks for your help, I have a further question, if I may. The way I worked around the problem was to change from using SaveChangesOptions.Batch to SaveChangesOptions.None. I'm wondering if there is any down side to this? Is it less efficient?
    Wednesday, May 25, 2011 9:25 PM