Hello Ricardo,

Thanks for the reply. However using a stateless session doesnt help my 
case. What I want, is an alternative means to changing the foreign key 
value. At the moment, the closes I have come to fully mapping the foreign 
key is:

Map(x => x.ParentID).ReadOnly();

which allows me to read the ID of the parent but of course I can't change 
it. 

On Wednesday, September 19, 2012 10:41:41 AM UTC+3, Ricardo Peres wrote:
>
> If you use stateless sessions you can work totally disconnected:
>
> ChildEntity.ParentEntity = new ParentEntity(){ Id = 100 };
>
> This is mostly the same as using ISession.Load(), because it won't go to 
> the database (if your entity is configured as lazy, that is).
>
> RP
>
> On Monday, September 17, 2012 4:24:47 PM UTC+1, Mike B wrote:
>>
>> Hello,
>>
>> What I need is to be able to map both foreign key and a reference to a 
>> parent object. For example:
>>
>>
>> class Parent
>>>      int                ParentID
>>>      List<Child>   Children 
>>>
>>  
>>>
>>
>>> class Child
>>>     int         ChildID
>>>     int         ParentID // foreign key
>>>     Parent   ParentEntity  
>>>  
>>> class ParentMap
>>>     HasMany(x => x.Children)
>>>           .KeyColumn("ParentID ")   // PROBLEM!
>>>           .Inverse()
>>>           .Cascade.All();
>>>
>>> class ChildMap
>>>     Map(x => x.ParentID);     // PROBLEM!
>>>     References(x => ParentEntity);
>>
>>
>> The reason behind this is that operations are done in a detached 
>> environment, and the detached environment doesn't "know" about NHibernate, 
>> so solutions like ChildEntity.ParentEntity = Sessions.Load(parentEntityID) 
>> are not acceptable. We explicitly need to work with the foreign key as a 
>> property.  Any help very appreciated
>>
>>

-- 
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/-/B_p18T6K0r4J.
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