Hello oscar, thanks for the reply. The problem isn't so much with the specific property that signifies a relationship. The problem is with any property at all, they are all set to null. For example, I want the property to have metadata about the parent, ie:
ParentEntity.ChildEntity.Name = "ParentEntity.ChildEntity" This can be accomplished easily durind the constructor phase of ParentEntity , but NHibernate resets the .Name to null. Any idea how to overcome this? On Monday, November 19, 2012 12:16:36 AM UTC+2, Oskar Berggren wrote: > > If you haven't told NHibernate about ParentEntityReference in any way, > then it will of course be null. > > "mapping is one way". But your classes have a bidirectional relationship - > why not tell NHibernate about this? > > Another way is to set ParentEntityReference inside the setter for > ParentEntity.ComplexProperty. It will only be non-null if the > ComplexProperty instance is actually "loaded through" ParentEntity, instead > of directly by id. > > There is also the NHibernate event listener system - perhaps you can do > something there. > > /Oskar > > > > 2012/11/18 Mike B <[email protected] <javascript:>> > >> So I have done some more experimentation. It seems that *all* properties >> that are set inside the constructor, are set to null (if applicable). >> >> Is there a way to set properties inside the constructor of the entities >> when using NHibernate? >> >> >> On Wednesday, November 14, 2012 11:23:50 PM UTC+2, Mike B wrote: >>> >>> I have these classes: >>> >>> ParentEntity : ISomeInterface >>> { >>> public ParentEntity() >>> { >>> ComplexProperty = new ComplexProperty { ParentEntityReference >>> = this }; >>> } >>> int ID {get; set;} >>> ComplexProperty ComplexProperty {get; set;} >>> } >>> >>> ComplexProperty >>> { >>> int ComplexPropertyID {get; set;} >>> ISomeInterface ParentEntityReference {get; set;} >>> } >>> >>> Mapping is one way, meaning thet ParentEntity has a "HasMany()" mapping >>> and that's it. >>> >>> While working with POCOs, everything is fine. I get the parent class, >>> and the child has a reference to the parent. When I retrieve the >>> ParentEntity object from the ORM though, The property: >>> ParentEntity.ComplexProperty.**ParentEntityReference == null ! Any Idea >>> how I get around this? And how to handle one way mappings in general? All I >>> need is a reference to the parent object inside the ComplexProperty >>> >> -- >> 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/-/wV7gFSWxnyIJ. >> >> To post to this group, send email to [email protected]<javascript:> >> . >> To unsubscribe from this group, send email to >> [email protected] <javascript:>. >> 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 view this discussion on the web visit https://groups.google.com/d/msg/nhusers/-/VDHXC0jq8ssJ. 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.
