2008-12-17 50 views
1

當我在Fluent NHibernate中工作時,我非常驚喜。我得到了具有主鍵列名稱的舊數據庫與我在域模型中的屬性不同。我敢肯定,我可以使用這個映射文件:我們能否在Fluent NHibernate中有主鍵列的自定義名稱?

<class name="Person"> 
    <id name="Id" column="CommentId"> 
     <generator class="native"/> 
    </id> 
    <property name="Description" type="String" /> 
</class> 

但我如何真正得到這個映射在流利NHibernate映射?

回答

1

以下流利-NHibernate的映射:

public class PersonMap : ClassMap<Person> 
{ 
    public PersonMap() 
    { 
     Id(x => x.Id, "CommentId") 
      .GeneratedBy.Native(); 

     Map(x => x.Description); 
    } 
} 

生成此XML映射:

<class name="Person" table="[Person]" xmlns="urn:nhibernate-mapping-2.2"> 
    <id name="Id" column="CommentId" type="Int32"> 
     <generator class="native" /> 
    </id> 
    <property name="Description" column="Description" length="100" type="String"> 
     <column name="Description" /> 
    </property> 
    </class> 
相關問題