It works! Thanks! But what does "inverse" mean? So many articles say that 
inverse = false means the child objects should be inserted first, then the 
parent object. And then the foreign key in the child table gets updated. 
Like this one: 
http://blog.jonathanoliver.com/2009/09/nhibernate-inverse-and-object-associations/
If a not-null="true" can let parent object get inserted first, what is the 
use of the inverse attribute?

On Tuesday, October 2, 2012 5:38:08 PM UTC+8, cremor wrote:
>
> Just add not-null="true" to the key element of your collection mapping.
>
> On Friday, September 21, 2012 11:40:11 AM UTC+2, Mouhong Lin wrote:
>>
>> 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.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/nhusers/-/tkUDpFHHOW0J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to