It's so much easier to do it in your domain model... with a 2-line
AddElement method in Entity.

    Diego


On Sat, Aug 28, 2010 at 12:22, Jacob Madsen <[email protected]> wrote:

> So you do not believe its possible to extend NHibernate with this
> responsibility?
>
>
> On Sat, Aug 28, 2010 at 5:08 PM, nadav s <[email protected]> wrote:
>
>> Read about mapping many-to-one
>> anyway, nhibernate will set the many to one property when you retrieve
>> elements from Db, but setting the many to one property when an element is
>> added to the entity is all up to you
>>
>> On Sat, Aug 28, 2010 at 5:58 PM, Jacob Madsen <[email protected]> wrote:
>>
>>> Hi there,
>>>
>>> I believe NHibernate might be able to help me set a "many-to-one
>>> relationship property", since it must have the necessary knownledge about
>>> the relationship. Maybe set it within an intercepter or listener?
>>>
>>> public class Entity
>>> {
>>>     public int Id { get; set; }
>>>
>>>     IList<Element> Elements { get; set; }
>>>
>>>     public Entity()
>>>     {
>>>         Elements = new List<Element>();
>>>     }
>>> }
>>>
>>> public class Element
>>> {
>>>     public int Id { get; set; }
>>>     public Entity RelationshipProperty { get; set; } // NH might be able
>>> to set this property when its comitting?
>>> }
>>>
>>> using (var session = sessionFactory.OpenSession())
>>> using (var tx = session.BeingTransaction())
>>> {
>>>     var entity = new Entity();
>>>
>>>     entity.Elements.Add(new Element()); // Instead
>>> of: entity.Elements.Add(new Element() { RelationshipProperty = entity
>>> });
>>>
>>>     session.Save(entity);
>>>
>>>     tx.Commit();
>>> }
>>>
>>> Cheers!
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "nhusers" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected]<nhusers%[email protected]>
>>> .
>>> For more options, visit this group at
>>> http://groups.google.com/group/nhusers?hl=en.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "nhusers" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected]<nhusers%[email protected]>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/nhusers?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<nhusers%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
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