您好,希望有人可以帮助我。
我有这样的情况:
用户实体存储我的所有用户(包括管理员)。
评论实体,存储针对用户的所有评论。
我的问题是我还在评论实体中存储发表评论的管理员的用户 ID。所以现在我的 Comment 实体有 2 个 userId 字段,并且在检索 User 实体时,它不会获取任何关联的评论。
我的映射代码如下:
在 User 实体内..
<set name="MemberComments" cascade="all-delete-orphan" inverse="true">
<key column="UserCommentId"/>
<one-to-many class="IlluminatiCoreUserComment"/>
</set>
在 UserComment 实体内
<id name="UserCommentId">
<generator class="identity"/>
</id>
<many-to-one name="User" class="IlluminatiCoreMember" column="UserId" not-null="true"/>
<property name="Comment" not-null="true"/>
<property name="CreatedTimeStamp" not-null="true"/>
<property name="ModifiedTimeStamp" not-null="true"/>
<many-to-one name="CommentedByUser" class="IlluminatiCoreMember" column="CommentedByUserId" not-null="true" inverse="false"/>
如何使 User 实体内的 MemberComments 仅指向 User 多对一字段?
感谢您提前的帮助
Hello hope someone can help me on this.
I have a situation where I have:
User entity which stores all my users including admins.
Comments entity which stores all comment against users.
my problem is I'm also storing within the comment entity the user id of the admin who made the comment. So now I have the Comment entity having 2 userId fields and when retrieving a User entity it wouldn't fetch any associating comments.
My mapping code is as below:
Within the User Entity..
<set name="MemberComments" cascade="all-delete-orphan" inverse="true">
<key column="UserCommentId"/>
<one-to-many class="IlluminatiCoreUserComment"/>
</set>
Within the UserComment Entity
<id name="UserCommentId">
<generator class="identity"/>
</id>
<many-to-one name="User" class="IlluminatiCoreMember" column="UserId" not-null="true"/>
<property name="Comment" not-null="true"/>
<property name="CreatedTimeStamp" not-null="true"/>
<property name="ModifiedTimeStamp" not-null="true"/>
<many-to-one name="CommentedByUser" class="IlluminatiCoreMember" column="CommentedByUserId" not-null="true" inverse="false"/>
How can I make MemberComments within the User entity point to just the User many-to-one field?
Thanks for your help in advance
发布评论
评论(1)
User 中的
元素应该具有 User 的 FK,而不是 UserComment 的 id。换句话说,与多对一、UserId 相同的列。
The
<key>
element in User should have the FK to User, not the id of UserComment.In other words, the same column as the many-to-one, UserId.