Fluent Nhibernate mapping related items

Posted by Josh on Stack Overflow See other posts from Stack Overflow or by Josh
Published on 2010-06-11T16:41:52Z Indexed on 2010/06/11 16:42 UTC
Read the original article Hit count: 164

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about fluent-nhibernate