We create the database using the schemaExport class of nHibernate. I now have an class with attributes from which we generated the nhibernate mapping. A part of this class is:
public class PluginInstance
{
...
[Bag(2, Name = "RouteParams", Access = "property", Table = "CMS_PluginInstanceRouteParams")]
[Key(3, Column = "ParamId")]
[Element(4, Column = "Param", Type = "string")]
public virtual IList<String> RouteParams
{
get { return _routeParamsField; }
set { _routeParamsField = value; }
}
...
}
The generated part of the nHibernate mapping is the following
<bag name="RouteParams" access="property" table="CMS_PluginInstanceRouteParams">
<key column="ParamId" />
<element column="Param" type="string" />
</bag>
For this property is correcty the "CMS_PluginInstanceRouteParams" table created when we call:
var schemaExport = new SchemaExport(configuration);
schemaExport.Create(false, true);
But I was wondering why this table does not have an primary key. The generated structure is
The column ParamId is correctly an foreign key to the table of the class PluginInstance and in the column Param are correctly the values of the property RouteParams stored.
Is there no need for an primary key on this table? Is it possible to set the primary key on this property using the NHibernate.Mapping.Attributes?