Validation rule to check for duplicate entity only fires when saving, not when adding the entity from the screen RRS feed

  • Question

  • I have a Businesses table, a Categories table a Listing table, and a ListingsTypes table, where the idea is that businesses can be listed in categories, and listings can be of various types. I would like to write a validation rule that ensures that each business can only have one listing of any type in each category.

    I added code for the Listings_Validate method, and checked if there was already a listing in there. If so, I add an entity error.

    This works fine, except that the error is only flagged up to the user when they try to save the data. At the moment, they can add duplicates, and won't get notified of the problem until they click the Save button. I would like it flagged as soon as the user tries to add the listing, ie from the pop-up window where they add an entity, or from the grid if they edit an existing listing in the grid.

    In this video, she does something similar, but is writing code against the product property of the OrderDetail entity. I can't do that as my Business entity has a Listings collection, not a single entity, and it won't allow me to write a validation rule against that. Also, this wouldn't make sense, as the Category entity also has a Listings collection, so I would have to write the same code twice. It seems logical to put the code on the Listing entity, but I want it run immediately, not wait until the user tries to save the data.

    Any idea how I can do this?Thanks

    If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at http://dotnetwhatnot.pixata.co.uk/
    Monday, August 29, 2011 4:35 PM


All replies