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 825515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:16:09+00:00 2026-05-15T03:16:09+00:00

If I have a Domain Model that has an ID that maps to a

  • 0

If I have a Domain Model that has an ID that maps to a SQL Server identity column, what does the POCO look like that contains that field?

Candidate 1: Allows anyone to set and get the ID. I don’t think we want anyone setting the ID except the Repository, from the SQL table.

public class Thing {
    public int ID {get;set;}
}

Candidate 2: Allows someone to set the ID upon creation, but we won’t know the ID until after we create the object (factory creates a blank Thing object where ID = 0 until we persist it). How would we set the ID after persisting?

public class Thing {
    public Thing () : This (ID: 0) {}
    public Thing (int ID) {
        this.ID = ID
    }
    private int _ID;
    public int ID {
        get { return this.ID;};
    }

Candidate 3: Methods to set ID?

Somehow we would need to allow the Repository to set the ID without allowing the consumer to change it. Any ideas? Is this barking up the wrong tree? Do we send the object to the Repository, save it, throw it away, then create a new object from the loaded version and return that as a new object?

  • 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-15T03:16:10+00:00Added an answer on May 15, 2026 at 3:16 am

    How about a public get accessor and an internal set accessor that throws InvalidOperationException if the underlying value is already non-zero?

    Obviously you already have some way of materializing the field so that you can even load the record. Why not just use the same mechanism? After all it’s not just identity values that you need to consider. It’s basically any value that can change in the database after an insert/update such as computed columns, columns affected by triggers, etc.

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

Sidebar

Related Questions

I have a class in my domain model root that looks like this: namespace
I have a Domain Model for Countries and States that looks like the following(see
I have a domain model that has the concept of an Editor and a
I have an object from my domain model that has a child object. How
Suppose I have a domain model that has 1:1 correspondence to the physical model.
I have a domain model that looks like this: case class Account(id: Int, name:
Let's say i have a Domain Model that im trying to make compatible with
I have two tables that are considered a single entity in my domain model.
I have a form that handles editing of a domain model (A). This domain
I currently have a client that wants me to 'abstract' out a domain model

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.