Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify table name in Fluent NHibernate ClassMap class?

I am newbie to NHibernate and trying to use Fluent for mapping. My entity class name is different from the database table name it has to be mapped to. I am using mapping class derived from ClassMap<>, but I can't specify the table name: the property TableName from ClassMap is read-only.

Thanks for your help.

like image 294
twk Avatar asked Mar 11 '09 09:03

twk


3 Answers

Use Table("table_name") instead.

like image 100
Spikolynn Avatar answered Nov 10 '22 19:11

Spikolynn


Does it work like?

public class UserAccountMap : ClassMap<UserAccount> {
    public UserAccountMap() {
        Table("User");
        Id(x => x.UserID, "UserID").GeneratedBy.Identity();
        Map(x => x.FirstName, "FirstName").Length(50)
            .Not.Nullable();
        Map(x => x.LastName, "LastName").Length(50)
            .Not.Nullable();
    }
}
like image 40
hardywang Avatar answered Nov 10 '22 21:11

hardywang


The example above lead me in the right direction. This worked for me. My class name is "Party" and my table name is "prty.Party".

public class PartyMap : ClassMap<Party>
{
    public PartyMap()
    {
     Table("prty.Party");
     Id(x => x.PartyID);
     Map(x => x.PartyTypeLID);
     Map(x => x.OrganizationTypeLID);
     Map(x => x.PreferredContactMethodLID);
     Map(x => x.PrimaryLanguageLID);
     Map(x => x.PartyVID);
     Map(x => x.BeginDate);
     Map(x => x.EndDate);
     Map(x => x.RowDescriptor);
     Map(x => x.RowModifiedDate);
     Map(x => x.RowModifiedBy);
     Map(x => x.RowCreatedDate);
     Map(x => x.RowCreatedBy);
    }        
}
like image 6
Phillip Houston Avatar answered Nov 10 '22 20:11

Phillip Houston