我看了教程 http://wiki.fluentnhibernate.org/Auto_mapping#Getting_started流利的nhibernate如何知道要訪問哪個表?
但我不明白如何訪問表?
我沒有給出任何命名轉換,那麼映射是如何完成的?
在hbm.xml
,有一個聲明:
<class name="Cat" table="Cat">
但在流暢沒有。
我看了教程 http://wiki.fluentnhibernate.org/Auto_mapping#Getting_started流利的nhibernate如何知道要訪問哪個表?
但我不明白如何訪問表?
我沒有給出任何命名轉換,那麼映射是如何完成的?
在hbm.xml
,有一個聲明:
<class name="Cat" table="Cat">
但在流暢沒有。
如果您使用類映射,使用表聲明:
public class ExampleMap : ClassMap<Example>
{
public ExampleMap()
{
Table("MyExampleTable");
Id(a => a.Id).GeneratedBy.Identity();
}
}
如果您使用自動映射,請參閱文檔在http://wiki.fluentnhibernate.org/Auto_mapping對於如何建立覆蓋
你絕對可以說明表在你的映射器中的名字。但是如果你有興趣知道它是如何自動映射的,那麼你需要了解Fluent NHibernate的慣例。
閱讀this公約章節。
流利的你會將你的表映射到一個類中。例如:
using FluentNHibernate.Mapping;
namespace Models.Mapping
{
public class CustomerMap : ClassMap<Customer>
{
public CustomerMap()
{
Table("Customer");
Id(customer => customer.Id);
Map(customer => customer.Name).Column("client_name").Not.Nullable();
Map(ssc => customer.ssc).Column("social_security_numer");
References(customer => customer.User);
}
}
}
這只是顯示如何映射您的表。這很簡單,你可以看到。你不會使用的hbm.xml到了地圖,並記得註冊您的映射,比如:
ISessionFactory SessionFactory = Fluently.Configure(configuration).Mappings(m =>
{
m.FluentMappings.AddFromAssemblyOf<CustomerMap>();
}).BuildSessionFactory();
只是一個簡單的例子,你可以找到更多的流暢參考。
我正在和同一個解決方案的朋友一起工作。他願意使用hbm.xml,所以他配置了SessionFactory = configuration.BuildSessionFactory();我可以添加我的映射配置嗎? –
什麼教程?你忘了鏈接。 – Oded