I am new to NHibernate and I am finding problem mapping two table relationships.
I have two tables cafe_table and cafe_table_group in SQL Server database. Both of them have auto-increment and Identity columns for their unique ID's .
Although foreign key is shown in the table, I will not have it.
This is my cafe_table.hbm.xml file:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping assembly="CafePOS" namespace="CafePOS" xmlns="urn:nhibernate-mapping-2.2">
<class name="CafePOS.CafeTable" table="cafe_table" lazy="true" >
<id name="cafe_table_id" column="cafe_table_id">
<generator class="identity" />
</id>
<property name="cafe_table_group_id">
<column name="cafe_table_group_id" sql-type="decimal" not-null="false" />
<many-to-one name="cafe_table_group" class="CafePOS.CafeTableGroup" column="cafe_table_group_id" fetch="select"/>
</class>
</hibernate-mapping>
My cafe_table.hbm.xml file:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping assembly="CafePOS" namespace="CafePOS" xmlns="urn:nhibernate-mapping-2.2">
<class name="CafePOS.CafeTableGroup" table="cafe_table_group" lazy="true" >
<id name="cafe_table_group_id" column="cafe_table_group_id">
<generator class="identity" />
</id>
<set name="cafe_table" table="`cafe_table`">
<key column="cafe_table_group_id"/>
<one-to-many class="CafePOS.CafeTable" fetch="select"/>
</set>
</class>
</hibernate-mapping>
cafe_table will have many-to-one relationship with cafe_table_group on cafe_table_group_id and cafe_table_group will have one-to-many relationship with cafe_table.
My model CafeTable class: namespace CafePOS {
public class CafeTable {
public virtual decimal cafe_table_id { get; set; }
public virtual decimal cafe_table_group_id { get; set; }
public virtual CafeTableGroup cafe_table_group { get; set; }
}
}
My CafeTableGroup model class:
namespace CafePOS {
public class CafeTableGroup {
public virtual decimal cafe_table_group_id { get; set; }
public virtual string cafe_table_group_name { get; set; }
public virtual IList<CafeTable> cafe_table { get; set; }
}
}
I just want this relationship for SELECT statement similar to INNER JOIN in SQL query.