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.
我的问题是我还在评论实体中存储了发表评论的管理员的用户ID。所以我现在让Comment实体有2个userId字段,当检索User实体时,它不会获取任何关联注释。
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
在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"/>
How can I make MemberComments within the User entity point to just the User many-to-one field?
如何在User实体中使MemberComments指向User多对一字段?
Thanks for your help in advance
感谢您的帮助
1 个解决方案
#1
0
The <key>
element in User should have the FK to User, not the id of UserComment.
User中的
In other words, the same column as the many-to-one, UserId.
换句话说,与多对一,UserId相同的列。
#1
0
The <key>
element in User should have the FK to User, not the id of UserComment.
User中的
In other words, the same column as the many-to-one, UserId.
换句话说,与多对一,UserId相同的列。