Hi Forum...
I try to connect to Tables with "one-to-many".
First of all, here my hbm.xml's:
Code:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="Database.Tables"
assembly="Database" >
<class
name="FgBlocks"
table="FgBlocks">
<id
name="Id">
<generator
class="guid" />
</id>
<property
name="BlockName"
length="255"
not-null="true"
unique="true" />
<property
name="FileName"
length="255" />
<property
name="BlockType"
not-null="true" />
<bag
name="FgBlockProperties"
table="FgBlockProperties"
cascade="all"
inverse="true">
<key
column="BlockId"
foreign-key="FK_Block" />
<one-to-many
class="Database.Tables.FgBlocksProperties, Database" />
</bag>
</class>
</hibernate-mapping>
the corresponding Class:
Code:
namespace Database.Tables
{
public class FgBlocks
{
private Guid _id;
private IList<FgBlocksProperties> _properties = new List<FgBlocksProperties>();
private string _blockName;
private string _fileName;
private int _blockType;
{
get { return _id; }
set { _id = value; }
}
public virtual IList<FgBlocksProperties> Properties
{
get { return _properties; }
set { _properties = value; }
}
public virtual string BlockName
{
get { return _blockName; }
set { _blockName = value; }
}
public virtual string FileName
{
get { return _fileName; }
set { _fileName = value; }
}
public virtual int BlockType
{
get { return _blockType; }
set { _blockType = value; }
}
///<summary>Standard Konstruktor</summary>
public FgBlocks()
{
}
/// <summary>
/// Konstruktor mit Blockname
/// </summary>
/// <param name="FgBlockName"></param>
public FgBlocks(string FgBlockName)
{
this.BlockName = FgBlockName;
}
}
}
The sub-table hbm:
Code:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="Database.Tables"
assembly="Database">
<class
name="FgBlocksProperties"
table="FgBlocksProperties">
<id
name="Id">
<generator
class="guid" />
</id>
<property
name="Block" />
<property
name="PropertyId"
not-null="true" />
<property
name="Attribute" />
<property
name="BlockId" />
<many-to-one
name="BlockID"
class="FgBlocks"
column="BlockId"
not-null="true"
foreign-key="FK_Block" />
</class>
</hibernate-mapping>
and it's Class:
Code:
namespace Database.Tables
{
public class FgBlocksProperties
{
private Guid _id;
private FgBlocks _block;
private long _propertyId;
private string _attribute;
private Guid _blockId;
public virtual Guid Id
{
get { return _id; }
set { _id = value; }
}
public virtual Guid BlockId
{
get { return _blockId; }
set { _blockId = value; }
}
public virtual FgBlocks Block
{
get { return _block; }
set { _block = value; }
}
public virtual long PropertyId
{
get { return _propertyId; }
set { _propertyId = value; }
}
public virtual string Attribute
{
get { return _attribute; }
set { _attribute = value; }
}
}
}
I hve massive problems to understand how the relation between the two tables have to be defined.
Could someone please comment / explain this to me?
Many thanks
Telefisch