需要帮助将这个映射文件从NHibernate转换为Fluent NHibernate

时间:2010-07-11 13:20:15

标签: fluent-nhibernate mapping

我想将此映射文件从NHibernate转换为Fluent NHibernate

    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
      <class name="CustomCollectionsBasic.Core.Category, CustomCollectionsBasic.Core" table="Categories">
        <id name="ID" column="CategoryID" unsaved-value="0">
          <generator class="identity" />
        </id>
    <property name="Name" column="CategoryName" />

    <bag name="ProductsInCategory" table="Products" cascade="all" inverse="true"
         collection-type="CustomCollectionsBasic.Data.Collections.PersistentProductsType, CustomCollectionsBasic.Data">
     <key column="CategoryID" />
     <one-to-many class="CustomCollectionsBasic.Core.Product,ustomCollectionsBasic.Core" />
    </bag>
  </class>
</hibernate-mapping>

我尝试通过NHibernateHbmToFluent转换它,结果是

public class CategoryMap: ClassMap<CustomCollectionsBasic.Core.Category>
{
    public CategoryMap()
    {
        Table("Categories");
        Id(x => x.ID)
            .GeneratedBy.
            .UnsavedValue(0);
        Map(x => x.Name, "CategoryName");
        HasMany<CustomCollectionsBasic.Core.Product>(x => x.ProductsInCategory)
            .AsBag()
            .KeyColumn("CategoryID")
            .Table("Products")
            .Inverse()
            .Cascade;
    }
}

但它不起作用。

关于如何映射这个的任何想法?

提前致谢。

1 个答案:

答案 0 :(得分:0)

    Id(x => x.ID)
        .GeneratedBy
        .Identity()
        .UnsavedValue(0);

我认为其他的东西都没问题