Mark Harold C. Rivera
Mark Harold C. Rivera

Reputation: 291

Naming Table and Columns in Fluent NHibernate

I tried to change the table and column names of my Employee entity by accessing the Table("") and Column("") attributes of its classmap in fluent Nhibernate.

public class EmployeeMap : ClassMap<Employee>
{
    public EmployeeMap()
    {
        Table("Employees");
        Id(x => x.Id);
        Map(x => x.FirstName)
           .Column("EmpFirstName");
        Map(x => x.LastName);
           .Column("EmpLastName")
        References(x => x.Store);
     }
 }

But instead of having the names I specified, the table and column names that appeared in my Postgresql db are all in lower case i.e. Employees -> employees and EmpFirstName -> empfirstname.

How can I set my table and column names to have the exact letter cases that I specified in my employee mapping?

Thanks, Mark

Upvotes: 2

Views: 1266

Answers (2)

whosrdaddy
whosrdaddy

Reputation: 11860

I prefer Sly's answer but you can get away with this (but it's ugly):

public class EmployeeMap : ClassMap<Employee>
{
    public EmployeeMap()
    {
        Table("Employees");
        Id(x => x.Id);
        Map(x => x.FirstName)
           .Column("\"EmpFirstName\"");
        Map(x => x.LastName);
           .Column("\"EmpLastName\"")
        References(x => x.Store);
     }
 }

EDIT here is link how to implement this via a naming strategy: http://manfredlange.blogspot.com/2011/04/fluent-nhibernate-postgresql-and.html

Upvotes: 3

Sly
Sly

Reputation: 15217

Try to setup autoquote option for NHibernate.

<property name="hbm2ddl.keywords">auto-quote</property>

My gues the problem is in this:

the identifiers FOO, foo, and "foo" are considered the same by PostgreSQL, but "Foo" and "FOO" are different from these three and each other.

Upvotes: 2

Related Questions