开发者

NHibernate Mapping + Iset

开发者 https://www.devze.com 2022-12-27 06:39 出处:网络
I have a mapping file <set name=\"Friends\" table=\"Friends\"> <key column=\"UserId\"/> <many-to-many class=\"User\" column=\"FriendId\"/>

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="User开发者_开发知识库Id"/>
      <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


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>.

0

精彩评论

暂无评论...
验证码 换一张
取 消