This project is read-only.

How to check existence of data before persisted

Aug 20, 2012 at 11:26 PM

How to check existence of data before it persisted so that a error message can be displayed to the end user.

Aug 22, 2012 at 9:03 AM

As a general comment:  please put more effort into explaining what it is that you are trying/wanting to do  -  with some example detail.  I would rather spend time trying to figure out an answer than trying to figure out what the question is.

My best guess is that you are wanting to save a new object, but wanting to check whether that new object would duplicate one already persisted in the database?  Is that correct?

If so: is the non-duplication enforced in the database (via uniqueness constraints) or are you wanting to enforce the uniqueness in the domain model without it being constrained in the database?  Is the uniqueness defined by all the properties on the object or just a subset (e.g. Name, Date)?

Aug 26, 2012 at 10:28 AM

"My best guess is that you are wanting to save a new object, but wanting to check whether that new object would duplicate one already persisted in the database?  Is that correct?"

Yes it is. And I have achieved this first using unique key in DB and catching the error in "public string OnPersistingError(Exception e)" , a Life Cycle Methods.

But after reading Dan's post, I have switched to "Validation" Method.

Thanks to all of you.