Why not do item.Bar = barRepository.RetrieveByCode(123); in the UI layer? (well, some inbetween service layer perhaps).
/Oskar 2010/6/22 Colin Bowern <[email protected]>: > I have an object where I maintain a relationship to another object: > > public class Foo { > public Bar Bar { get; set; } > } > > In the mapping I reference Bar to that I can maintain the relationship > - I don't want the parent object to update properties in the child, > just the existence of the relationship: > > References(x => x.Bar, "BarId") > .Cascade.None(); > > In the UI layer I create the relationship using a property which is > not the underlying primary key: > > item.Bar = new Bar { Code = "123" }; > > In the repository layer I hydrate the object if it doesn't have the > primary key populated: > > if(item.Bar.Id == null) > { > item.Bar = barRepository.RetrieveByCode(item.Bar.Code); > } > > When I the RetrieveByCode line runs (which is a Criteria.UniqueResult > under the covers) I get a TransientObjectException telling me that > "the object references an unsaved transient instance - save the > transient instance before flushing" for the Bar type. > > When I run the same code path without creating the temporary Bar > object it works. It appears that the Bar created as a temporary oject > is tracked by NHibernate, yet I want it to forget that it ever existed > as it is only a placeholder. > > Any thoughts on how to achieve this? > > -- > 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. > > -- 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.
