Ah sorry I forgot to ask you about Optimistic-Lock...Are your entities even versioned ?
2009/7/29 Fabio Maulo <[email protected]> > If you really want avoid any kind of select you can do it in NHdelete > from Article a where a in (select au.Articles from Author au where au.id = > :pAuthor) > SetInt32("pAuthor", author. AuthorID) > > and then > delete from Article a where a.id = :pAuthor > SetInt32("pAuthor", author. AuthorID) > > 2009/7/29 e36M3 <[email protected]> > >> >> Fabio, thanks for your reply. The reason author.Articles is null is >> because the calling application created this Author instances and >> assigned it an id. Something like this Author authorToDelete = new >> Author() { AuthorID = 5 };. Once this is done this code (website) >> sends it to the web service which than needs to delete the author, >> however it also needs to delete all of its children. Being that the >> object was created outside of the NH context, there is no proxy for >> author.Articles when the web service receives it. I attempted to use >> session.Lock and session.Merge, however there is still no proxy >> instance for author.Articles, therefor I cannot delete the articles >> directly by looping through author.Articles. Obviously I can query >> the database to obtain the author object from the session and then use >> it's proxy but I would love to avoid that select. >> >> On Jul 29, 10:37 am, Fabio Maulo <[email protected]> wrote: >> > To reattach an object to a session you have various >> > ways.session.Lock(LockMode.None), >> > session.Merge and so on. >> > In your case I don't understand "author.Articles is always null" >> because >> > the "author" instance come from another method out-side NH >> responsibility. >> > >> > 2009/7/29 e36M3 <[email protected]> >> > >> > >> > >> > >> > >> > > Hello all, after creating a sample web application POC using the >> > > Entity Framework I am attempting to do the same with NH. I ran into >> > > what is probably a very simple issue however I can't quite find the >> > > solution. My web application is passing an Author object to my service >> > > which then supposed to delete the author and all of its children >> > > (Articles). I am not utilizing cascading delete so I am trying to nuke >> > > those articles manually before I nuke the author, however I can't get >> > > the author.Articles list to populate. In the below example >> > > author.Articles is always null. I understand I must be missing >> > > something regarding the disconnected nature of what I am attempting to >> > > do here, but in Entity Framework I was able to simply attach my entity >> > > to the ObjectContext (session in NH) and go from there as usual. I >> > > recognize that I could simply query first for the Author instance >> > > first, but the whole point is to avoid that query as I already have >> > > that object being passed into the service. When I put a break-point >> > > on the author I realize that there is no proxy class associated with >> > > author.Articles, how do I get that proxy class to appear? Thank you. >> > >> > > public void DeleteAuthor(Author author) >> > > { >> > > using (ISession session = GetSession()) >> > > { >> > > using (ITransaction tx = session.BeginTransaction()) >> > > { >> > > try >> > > { >> > > foreach (Article article in author.Articles) >> > > { >> > > session.Delete(article); >> > > } >> > >> > > session.Delete(author); >> > > session.Flush(); >> > > tx.Commit(); >> > > } >> > > catch (HibernateException) >> > > { >> > > tx.Rollback(); >> > > throw; >> > > } >> > > } >> > > } >> > > } >> > >> > -- >> > Fabio Maulo >> >> >> > > > -- > Fabio Maulo > -- Fabio Maulo --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
