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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:03:56+00:00 2026-05-31T16:03:56+00:00

Question regarding fluent nHibernate table mappings: Apparently I was under the mistaken impression, that

  • 0

Question regarding fluent nHibernate table mappings:

Apparently I was under the mistaken impression, that with an ORM tool, such as nHibernate, one could gain database independence – at least in table creation.

Now, I have an automated tool ( http://nmg.codeplex.com ), which creates fluent nHibernate mappings for me.
It also works fine (though only if ALL tables have a primary key…)

Here a good representative example for such a mapping as it is created by the program

public class ELMAH_ErrorMap : ClassMap<ELMAH_Error> 
{

    public ELMAH_ErrorMap() 
    {
        Table("ELMAH_Error");
        LazyLoad();
        Id(x => x.ErrorId).GeneratedBy.Assigned().Column("ErrorId");
        Map(x => x.Application).Column("Application").Not.Nullable().Length(60);
        Map(x => x.Host).Column("Host").Not.Nullable().Length(50);
        Map(x => x.Type).Column("Type").Not.Nullable().Length(100);
        Map(x => x.Source).Column("Source").Not.Nullable().Length(60);
        Map(x => x.Message).Column("Message").Not.Nullable().Length(500);
        Map(x => x.User).Column("User").Not.Nullable().Length(50);
        Map(x => x.StatusCode).Column("StatusCode").Not.Nullable();
        Map(x => x.TimeUtc).Column("TimeUtc").Not.Nullable();
        Map(x => x.Sequence).Column("Sequence").Not.Nullable();
        Map(x => x.AllXml).Column("AllXml").Not.Nullable().Length(1073741823);
    }
}

Apparently, problem #1 was this line

Map(x => x.User).Column("User").Not.Nullable().Length(50);

Because user is a protected keyword in MS-SQL (and postgre as well).
So schema-export failed with syntax error near “User”.

Now, obviously this is solvable by enclosing the column (or table) name in the respective escape characters ([] for MS-SQL, “” for PostGreSQL)

So I changed

Map(x => x.User).Column("User").Not.Nullable().Length(50);

to

Map(x => x.User).Column("[User]").Not.Nullable().Length(50);

and it worked fine.

Then on PostGre, I had to change

Map(x => x.User).Column("[User]").Not.Nullable().Length(50);

to

Map(x => x.User).Column("\"User\"").Not.Nullable().Length(50);

because postgre uses this other escape sequence…

So now, do I have to create a separate mapping for every db system ?
(MySQL has another escape character as well…, wondering what FireBird uses)
ARGH ?!?

And another problem that exists as well:
For every table & column that isn’t enlosed in quotation marks, PostGre changes the table/column name to lowercase, which is “fine” (but only because it isn’t case sensitive), but if the name is encosed in quotation marks, it becomes case-sensitive…

Then, I do have some 200 views to port…
I don’t actually want to have to write a parser just to enclose every column of every view (as well as table and view names) in whatever quotes used by whatever db…

Is there a way to tell fluent/nHibernate to escape the table & column names for me (either always, but preferably only if necessary) ?

The funny thing is, my own DB isn’t actually the problem (I prefix all of my 200 tables with T_ and every column with some table id), the problem are all those crappy 3rd party components (like ELMAH or Session/Membership providers, etc.), that have been written by people who… [self censored]

  • 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-31T16:03:57+00:00Added an answer on May 31, 2026 at 4:03 pm

    Maybe you did not set the property hbm2ddl.keywords (should be on by deafult).

    Try look at this post from Fabio Maulo.

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

Sidebar

Related Questions

A quick question regarding the java.lang.VerifyError exception. Suppose I get an error that looks
Question follows on from Fluent NHibernate + multiple databases (no need to follow this
One question regarding whether the following code should yield a compiler warning or not
simple question regarding HQL(Hibernate query language) so i have user class , that can
Quick question regarding the OAuth2 Spec, in particular section 5.1.5 . Reading that spec,
Just had a question regarding the UILabel class. I know that the UITextField control
I have a question regarding jQuery. I have multiple images that are, in essence,
I have a question regarding class design. I want to have a class that
I have a question with fluent interfaces. We have some objects that are used
I have a question regarding regarding the permissions. I believe that the 3 marks

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.