Hello all,
I have a "Message" table:
- MessageId (guid)
- Subject
- Body
and "Comment" table
- CommentId (guid)
- ContainerId (guid)
- Content
The "ContainerId" refers to MessageId or CommentId.
If "ContainerId" refers to MessageId then it means that Comment replies to a Message.
If "ContainerId" refers to CommentId then it means that Comment replies to a Comment.
Here is my message class:
Code:
public class Message : ProjectEntity
{
public Message()
{
}
///<summary>
/// Gets or sets the MessageId of the Message.
///</summary>
///
public Guid MessageId
{
get
{
return this.messageId;
}
set
{
this.messageId = value;
}
}
private Guid messageId = Guid.Empty;
///<summary>
/// Gets or sets the Subject of the Message.
///</summary>
///
public string Subject
{
get
{
return this.subject;
}
set
{
this.subject = value;
}
}
private string subject = string.Empty;
///<summary>
/// Gets or sets the Body of the Message.
///</summary>
///
public string Body
{
get
{
return this.body;
}
set
{
this.body = value;
}
}
private string body = string.Empty;
Here is Comment class:
Code:
public class Comment
{
public Comment()
{
}
#region Public Properties
///<summary>
/// Gets or sets the CommentId of the Comment.
///</summary>
///
public Guid CommentId
{
get
{
return this.commentId;
}
set
{
this.commentId = value;
}
}
private Guid commentId = Guid.Empty;
///<summary>
/// Gets or sets the Message of the Comment.
///</summary>
///
public Message Message
{
get
{
return this.message;
}
set
{
this.message = value;
}
}
private Message message;
///<summary>
/// Gets or sets the Message of the Comment.
///</summary>
///
public Comment Parent
{
get
{
return this.parent;
}
set
{
this.parent = value;
}
}
private Comment parent;
....
and here is my mapping file:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Blog.Comment, Blog" table="Blog_Comments" lazy="false">
<id name="CommentId" column="CommentId" type="Guid">
<generator class="guid" />
</id>
<many-to-one cascade="none" name="Message" class="Blog.Message, Blog" column="ContainerId" foreign-key="MessageId" />
<many-to-one cascade="none" name="Parent" class="Blog.Comment, Blog" column="ContainerId" foreign-key="CommentId" />
<property name="Content" type="string"/>
</class>
</hibernate-mapping>
However I always receive error "Column name 'ContainerId' appears more than once in the result column list" when trying to save a Comment.My question is that if NHibernate supports mapping 1 column to multiple properties, in this case this is "ContainerId" column and 2 properties are Message and Parent.
Thanks,