Tutorial :need help to convert this mapping file from NHibernate to Fluent NHibernate



Question:

i want to convert this mapping file from NHibernate to 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>  

I try to convert it by NHibernateHbmToFluent and the result is

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;      }  }  

but it not working.

Any ideas on how to map this?

Thanks in advance.


Solution:1

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

I think the other stuff is OK


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »