Fluent Nhibernate mapping related items
- by Josh
I am trying to relate 2 items. I have a table that is simply an Id field, and then 2 columns for the Item Id's to relate. I want it to be a 2 way relationship - that is, if the items appear twice in the table, I only want one relationship connection back.
So, here's my item:
public class Item
{
public virtual Guid ItemId {get; set;}
public virtual string Name {get; set;}
public virtual IList<Item> RelatedItems {get; set;}
}
The table for relating the items looks like this:
CREATE TABLE RelatedItems
(
RelatedItemId uniqueidentifier NOT NULL,
ItemId uniqueidentifier NOT NULL,
RelatedId uniqueidentifier NOT NULL,
CONSTRAINT PK_RelatedItems PRIMARY KEY CLUSTERED (RelatedItemId)
)
What is the best way to map this connection?