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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:36:39+00:00 2026-06-16T21:36:39+00:00

I’m following a database first approach in a sample app. The POCO classes are

  • 0

I’m following a database first approach in a sample app. The POCO classes are generated via t4 template and it will have the Identity properties that it carry from the database. For some classes which I use as entities in the domain, the type of the id can be int, string & Guid.

I don’t see a problem with ids that are string or Guid which I can generate in the domain and pass that to the repository. In the case of int also I can do that, but I want to take advantage of the AUTOINCREMENT option of the SQL Database.

My questions are:

  1. Who’s responsibility is to generate the Identity for the Entity. Is it the domain or the repository?

  2. How the syncing of identities can be done between the repositories and the domain? For example, I can create an id of 1000 for a Customer in the domain, and ask the Repository to save it. When the repository saves it, the new identity may be 2000 (the AUTOINCREMENT option sets the new identity). Now the two entities are different, and if the Customer entity in the domain (assume it is cached for future operations) is used with other entities like Department, it can cause problems in the domain. The cached entity (Customer) in the domain which has the id of 1000 will be saved as a new entity in the SQL datastore. The repository does not know whether the Customer is cached or new.

  • 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-06-16T21:36:40+00:00Added an answer on June 16, 2026 at 9:36 pm

    Who’s responsibility is to generate the Identity for the Entity. Is it
    the domain or the repository?

    The identity of an entity can be assigned by the domain either directly or via client request. This type of identity is usually generated with a Guid or another universally unique value. The identity can also be assigned by the repository to reflect a database generated identity such as an incremental identity column.

    How the syncing of identities can be done between the repositories and
    the domain?

    When an entity’s identity is sourced from a database generated identity column, the domain should not assign its own identity. A transient entity with an integral identity will initially have identity value 0. When the transient entity is made persistent, the repository will assign the identity value. At that point, as you point out, there may some issues with cached instances of the newly persistent entity instance since the identity value has changed. There are a few ways to resolve these issues, but I try to avoid referencing transient entities in caches (or anywhere else) in the first places. This can be more easily done by making sure an entity isn’t referenced in many places until it is made persistent. If you do end up referencing a transient entity instance in various places, you can make sure that its .NET runtime identity remains the same for the lifetime of the instance. To do this, you have to compare entities via object.ReferenceEquals before the identity value check and you have to cache the hash-code generated via GetHashCode for the duration of the object lifetime.

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a reasonable size flat file database of text documents mostly saved in
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I have a small JavaScript validation script that validates inputs based on Regex. I

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.