I turn to Fluent NHibernate - the only problem I have encountered so far is that you cannot specify a foreign key name in a unified subclass mapping.
Does anyone have a solution for this or a workaround?
I found this post , but the sentence was clearly not added to the code.
I wish I couldnβt configure the code myself.
Any help would be great ...
Example:
public class Product { public string Name { get; set; } } public class Hammer : Product { public string Description { get; set; } } public class ProductMap : ClassMap<Product, long> { public ProductMap() { Polymorphism.Implicit(); Map(x => x.Name); } } public class HammerMap : SubclassMap<Hammer> { public HammerMap() { Extends<Product>(); } }
This generates something like:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="field.camelcase-underscore" auto-import="false" default-cascade="none" default-lazy="true"> <class xmlns="urn:nhibernate-mapping-2.2" dynamic-insert="true" dynamic-update="true" mutable="true" polymorphism="implicit" optimistic-lock="version" name="Domain.Product, Domain" table="Product"> <id name="Id" type="System.Int64"> <column name="Id" /> <generator class="native"> <param name="sequence">ProductId</param> </generator> </id> <property name="Name" type="System.String"> <column name="Name" /> </property> <joined-subclass name="Domain.Hammer, Domain" table="Hammer"> <key> <column name="Product_Id" /> </key> <property name="Description" type="System.String"> <column name="Description" /> </property> </joined-subclass> </class> </hibernate-mapping>
Note that there is no foreign key name in the hbm mapping file, as in:
<joined-subclass name="Domain.Hammer, Domain" table="Hammer"> <key column="Product_Id" foreign-key="FK_Hammer_Product"/> </joined-subclass>
source share