3

I just started learning Nhibernate and Fluent Nhibernate. I want to specify table name when I create my mapping class.

Entity name in application is "CustomerOrders" but in the oracle database, table name is "CUSTOMER_ORDERS".

I learnt from googling that I can use "WithTable" to specify database table name.

I am not sure how to use it and where as Vs2008 didn't find the method.

Thanks

dove
  • 20,469
  • 14
  • 82
  • 108
AlterWorld
  • 429
  • 1
  • 6
  • 18

2 Answers2

4
public class CustomerOrdersMap : IAutoMappingOverride<CustomerOrders>
    {
        public void Override(AutoMapping<CustomerOrders> mapping)
        {
            mapping.Table("CUSTOMER_ORDERS");


        }
    }
dove
  • 20,469
  • 14
  • 82
  • 108
  • @Thakkar i'm not sure from question how much more you would need specifically, so just ask if you want more context – dove Oct 16 '09 at 15:21
  • Dove, Table names and field names contains underscores and I do not have underscores in any entity class name or properties. I am not using AutoMapping because of these reason. I am extending from ClassMap manually. Now, is there a way to map field names as well with AutoMapping or map to a table name using ClassMap? Please advise. – AlterWorld Oct 16 '09 at 15:33
  • @Thakkar is there a convention of any kind between properties and table names. if it was consistant in some way, a convention could be written for it. for example all my foreign key names have FK as suffix in my databases. – dove Oct 16 '09 at 15:45
  • Dove, field names do not have any name patterns. The underscores appear randomly. e.g. Table name: Customer_Orders Field names: ID, Order_ID, Order_Item_ID, Item_Info, Comments, etc.. Unfortunately, I cannot change the database as other existing systems are using it. I see a "Table" method in the FluentNHibernate.Mapping.ClassMap. Do you think It will map the class to appropriate table? – AlterWorld Oct 16 '09 at 15:58
2

WithTable was renamed to Table for the 1.0 release. It was mentioned in the release notes (first bullet point).

James Gregory
  • 14,173
  • 2
  • 42
  • 60