Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 925465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:31:28+00:00 2026-05-15T19:31:28+00:00

I am going though this msdn article by noted DDD expert Udi Dahan ,

  • 0

I am going though this msdn article by noted DDD expert Udi Dahan, where he makes a great observation that he said took him years to realize; “Bringing all e-mail addresses into memory would probably get you locked up by the performance police. Even having the domain model call some service, which calls the database, to see if the e-mail address is there is unnecessary. A unique constraint in the database would suffice.”

In a LOB presentation that captured some add or edit scenario, you wouldn’t enable the Save type action until all edits were considered valid, so the first trade-off doing the above is that you need to enable Save and be prepared to notify the user if the uniqueness constraint is violated. But how best to do that, say with NHibernate?

I figure it needs to follow the lines of the pseudo-code below. Does anyone do something along these lines now?

Cheers,
Berryl

try {}
catch (GenericADOException)
{
    // "Abort due to constraint violation\r\ncolumn {0} is not unique", columnName)
    //(1) determine which db column violated uniqueness
    //(2) potentially map the column name to something in context to the user
    //(3) throw that can be translated into a BrokenRule for the UI presentation
    //(4) reset the nhibernate session
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T19:31:28+00:00Added an answer on May 15, 2026 at 7:31 pm

    The pessimistic approach is to check for unique-ness before saving; the optimistic approach is to attempt the save and handle the exception. The biggest problem with the optimistic approach is that you have to be able to parse the exception returned by the database to know that it’s a specific unique constraint violation rather than the myriad of other things that can go wrong.

    For this reason, it’s much easier to check unique-ness before saving. It’s a trivial database call to make this check: select 1 where email = 'newuser@somewhere.com'. It’s also a better user experience to notify the user that the value is a duplicate (perhaps they already registered with the site?) before making them fill out the rest of the form and click save.

    The unique constraint should definitely be in place, but the UI should check that the address is unique at the time it is entered on the form.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been going through this excellent article http://msdn.microsoft.com/en-us/library/ms972976.aspx that says ViewState is not responsible
Well, I was going through this excellent article on MSDN about Base Class Usage
This is probably going to sound like a sci-fi request, though – is there
I was going through this article : http://www.ajaxline.com/32-tips-to-speed-up-your-mysql-queries at point#4 , it states :
In C following this article ( http://blogs.msdn.com/oldnewthing/archive/2006/12/21/1340571.aspx ), we have succesfully been able to
So I'm going through this tutorial that seems so simple but I can't seem
As I was going through MSDN on the threading topic I found out that
I have a few different problems going on, I hope though this example is
I am going through this tutorial , but I already had Ruby 1.8.7 installed.
I am going through this document and this is what I gathered. <Esc> Escape

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.