Just add not-null="true" to the key element of your collection mapping.
Hi guys,
This is the models:
public class BlogPost {
public virtual int Id { get; set; }
public virtual IList<Comment> Comments { get; set; }
}
public class Comment {
public virtual int Id { get; set; }
public virtual string Content { get; set; }
// public virtual BlogPost BlogPost { get; set; }
}
Notice the commented line above.
I do NOT want the bidirectional association between BlogPost and Comment.
I want BlogPost to have a Comments collection, but do not want Comment to have a reference back to BlogPost.
As far as I know, this requires the mapping of Comments collection to be inverse = "false", and this requires the foreign key (BlogPostId) in the Comment table to be nullable. But from the database modeling's point of view, the foreign key BlogPostId should be not-null.
So, I want the foreign key BlogPostId in the Comment table to be not-null, while still keeping the association unidirectional, that is, remove the BlogPost property from Comment class. Can I do that? Thanks
BTW: Could anyone who is the manager of this group add me to the group? Now I can't publish posts without your verification. :-( Thanks.