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

  • Home
  • SEARCH
  • 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 726469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:27:20+00:00 2026-05-14T06:27:20+00:00

In DDD you should never let your entities enter an invalid state. That being

  • 0

In DDD you should never let your entities enter an invalid state. That being said, how do you handle the validation of a unique constraint?

The creation of an entity is not a real problem. But let say you have an entity that must have a unique name and there is a thousand instances of this entity type – they are not in memory but stored in a database. Now let say you want to rename an instance.

You can’t just use a setter… the object could enter an invalid state – you have to validate against the database.

How do you handle this scenario in a web environment?

  • 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-14T06:27:21+00:00Added an answer on May 14, 2026 at 6:27 am

    A uniqueness constraint can be reduced to a persistence exception, rather than being seen as an “invalid state”. It’s not an invalid state until the object is persisted. Uniqueness only makes much sense in the context of persistence. Realistically, you can put this kind of rule in your validation mechanism to help reduce the likelihood of this error, but in any real multiuser system, you can’t be guaranteed of uniqueness until a successful unit of work completes the persistence action.

    So you may want this in your validation mechanism, but you must enforce it in your persistence layer.

    I’m generally a fan of DDD as a methodology, but I think that the “don’t allow objects to get into invalid states” can require some tortuous abstractions. In a web application, having a separate “View Model” is one possible solution, as an intermediary layer before persistence, but I don’t usually do that until I’m convinced it will cause me less pain than the simpler alternative.

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

Sidebar

Related Questions

I'm learning about DDD, and have come across the statement that value-objects should be
One of the tenants of DDD is to not allow your objects to enter
Going to develop a search engine. I'm wondering how my DDD should look. Sorting
Can/Should my POCO's encompass multiple Databases if applicable? The reason I ask is that
I'm still wrapping my head around DDD, and one of the stumbling blocks I've
This is re-posted from something I posted on the DDD Yahoo! group. All things
I'm trying to understand the concepts behind DDD, but I find it hard to
I have started using Linq to SQL in a (bit DDD like) system which
After spending a couple months studying DDD methodology, I've now began to apply these
I'm working on an event-sourced CQRS implementation, using DDD in the application / domain

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.