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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:53:07+00:00 2026-06-04T22:53:07+00:00

I’ve an entity with assigned string Id on NHibernate and I’ve a little problem

  • 0

I’ve an entity with assigned string Id on NHibernate and I’ve a little problem when get an entity by Id.

Example…

Suppose that have a database record like this…

Id    Description
-------------------
AAA   MyDescription

now, if I use “Get” method using search id “aaa”…

MYENTITYTYPE entity = Session.Get<MYENTITYTYPE>("aaa")

return right entity but Id field (entity.Id) is “aaa”, while I wish it were equal to “AAA”.

In summary I would like that “Get” method return the id identical to the one stored in the database…with the same case.

Is possible? How can I do?

  • 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-04T22:53:09+00:00Added an answer on June 4, 2026 at 10:53 pm

    Interesting question. My guess is that it’s not possible, because the Id might exist before the DB call. Consider the following:

    var foo = session.Load<Foo>("aaa"); //no DB call, foo is a proxy
    Console.WriteLine(foo.Id); //Prints "aaa";
    var bar = foo.Bar; //Forces loading
    Console.WriteLine(foo.Id); //No matter what, the Id can't change at this point
    

    This illustrates another reason why primary keys with meaning are usually a bad idea, especially if their input is not controlled.

    Now, if instead of Get you use a query, you will get the right-cased Id:

    //example with LINQ; you can use HQL, Criteria, etc
    var foo = session.Query<Foo>().Single(x => x.Id == "aaa");
    

    The drawback is that you will always go to the DB, even if the entity is already loaded.

    Now, if you defined your entity as {Id, Code, Description}, where Id is a synthetic POID (I recommend Hilo or Guid) and Code is the existing string Id, you will avoid potential bugs caused by using Get instead of a query with the code.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
Specifically, suppose I start with the string string =hello \'i am \' me And
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string
I have a reasonable size flat file database of text documents mostly saved in
I have some data like this: 1 2 3 4 5 9 2 6

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.