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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:41:22+00:00 2026-05-31T11:41:22+00:00

I am working with brownfield database that uses strings as primary keys. Using Fluent

  • 0

I am working with brownfield database that uses strings as primary keys.
Using Fluent NHibernate with Sqlite (in-memory provider for unit testing) and SQL Server 2005.

I have the following entity:

public class Entity
{
    public virtual DateTime TimeStamp { get; set; }

    public virtual string Name { get; set; }
}

With this mapping:

public class EntityMap : ClassMap<Entity>
{
    public EntityMap()
    {
        Map(_ => _.TimeStamp);
        Id(_ => _.Name).CustomType("AnsiString");
    }
}

However it does not work saying NHibernate.TypeMismatchException : Provided id of the wrong type. Expected: System.Int32, got System.String

How make this work? Also, is there any good documentation about fluent nhibernate available?

Thanks in advance.

  • 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-31T11:41:23+00:00Added an answer on May 31, 2026 at 11:41 am

    If you are using strings as your primary keys you’ll probably have to do something like this:

    public class EntityMap : ClassMap<Entity>
    {
        public EntityMap()
        {
            Id(x => x.Name).GeneratedBy.Assigned();
            Map(x => x.TimeStamp);
        }
    }
    

    From the nhibernate documentation:

    5.1.4.7. Assigned Identifiers

    If you want the application to assign identifiers (as opposed to
    having NHibernate generate them), you may use the assigned generator.
    This special generator will use the identifier value already assigned
    to the object’s identifier property. Be very careful when using this
    feature to assign keys with business meaning (almost always a terrible
    design decision).

    Due to its inherent nature, entities that use this generator cannot be
    saved via the ISession’s SaveOrUpdate() method. Instead you have to
    explicitly specify to NHibernate if the object should be saved or
    updated by calling either the Save() or Update() method of the
    ISession.

    Also here is a related article. It is a bit dated but still applies to your situation:

    http://groups.google.com/group/fluent-nhibernate/browse_thread/thread/6c9620b7c5bb7ca8

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

Sidebar

Related Questions

Working with an Oracle 9i database from an ASP.NET 2.0 (VB) application using OLEDB.
Working with a SqlCommand in C# I've created a query that contains a IN
Working on a project that parses a log of events, and then updates a
Working in Eclipse on a Dynamic Web Project (using Tomcat (v5.5) as the app
Working on an extension that use the new experimental devtools apis. How do you
I've just started working on a brownfield ASP.NET 2.0 Web Application. As with a
Working sample using one Table SELECT t.* FROM ( SELECT TITLE.name, (TITLE.value-TITLE.msp) AS Lower,
Working with a Lucene index, I have a standard document format that looks something
Working with SSRS and a SQL 2000 source, I have a stored procedure that
Working against jQuery 1.3.2 I'm looking for best practices that implement the typical '

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.