I am trying to create a Unique Key on a class that includes the foreign key to its parent. However, I get the following error: "Could not determine type for Parent". Below is the class and Fluent NHibernate mapping. I get that it is unable to figure out an SQL type for the Parent class, since it is just a proxy for the ParentFk field, but not sure what more to do to facilitate the translation:
Class
public class Item : BaseEntity
{
#region Properties
[DomainSignature]
public virtual string ItemNumber { get; set; }
[NotNull]
[DomainSignature]
public virtual Parent Parent { get; set; }
[DomainSignature]
public virtual long Iteration { get; set; }
remainder elided....
}
Mapping Override
public void Override(AutoMapping<Item> mapping)
{
mapping.Map(t => t.ItemNumber).UniqueKey("UIX_Item_NaturalKey").Not.Nullable();
mapping.Map(t => t.Iteration).UniqueKey("UIX_Item_NaturalKey").Not.Nullable();
mapping.Map(t => t.Parent, "ParentFk").UniqueKey("UIX_Item_NaturalKey").Not.Nullable();
}
So, is there a way to create a Unique Key that includes a Foreign Key, and, in this case, given that I have the DomainSignature attribute on all of the fields anyway, is it necessary?
Thanks!