jack
jack

Reputation: 1

NHibernate Mapping + Iset

I have a mapping file

<set name="Friends" table="Friends">
  <key column="UserId"/>
  <many-to-many class="User" column="FriendId"/>
</set>

I would like to specify extra columns for the friend table this creates.

For example Approve (the user must approve the friend request)

Is there a easy way?

And update

    <?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping namespace="MyVerse.Domain" assembly="MyVerse.Domain" xmlns="urn:nhibernate-mapping-2.2">
  <class name="User" table="[User]" lazy="true">
    <id name="Id" type="Guid">
      <generator class="guid" />
    </id>
    <property name="DateCreated" type="DateTime" not-null="true" />
    <property name="Deleted" type="Boolean" not-null="true" />
    <property name="Firstname" type="String" length="100" not-null="true" />
    <property name="Lastname" type="String" length="100" not-null="true" />
    <bag name="Friends" table="[Friend]">
      <key column="UserId"/>
      <many-to-many class="Friend" column="FriendId"/>

    </bag>

  </class>
  <class name="Friend" table="[Friend]" lazy="true">
    <id name="Id" type="Guid">
      <generator class="guid" />
    </id>
    <property name="DateCreated" type="DateTime" not-null="true" />
    <property name="Approved" type="Boolean" not-null="true" />
  </class>
</hibernate-mapping>

Will cause a link to the friend table from the friend table

Upvotes: 0

Views: 295

Answers (1)

Diego Mijelshon
Diego Mijelshon

Reputation: 52735

If a set has "extra properties", you must convert it into a proper entity.

So, a User doesn't have an ISet<User>; it has an ISet<Friend>.

Upvotes: 1

Related Questions