my advise was not get the collection through CreateQuery but was *delete the
collection through*.

2009/7/29 e36M3 <[email protected]>

>
> You are correct, I did not mean the collection wouldn't result in a
> select, I just meant that I did not want to do the initial select to
> get the Author instance from the session.  Your suggestion to get the
> children through session.CreateQuery is excellent, I was able to
> achieve what I wanted in the same number of sql statements as
> otherwise would have been created by NH if I got the author directly
> from the session.  Mission accomplished.  As far as versioning I am
> not doing so right now, I do understand the implications.  Once gain,
> thank you very much for your help.
>
> On Jul 29, 1:33 pm, Fabio Maulo <[email protected]> wrote:
> > well... I'm pretty sure that even EF is running a select to db because
> with
> > what you are doing there is no way to have the collection filled without,
> at
> > least, a select or two (have a look to MsSQL profiler).
> > In merge there is no proxy because you should specify cascade="merge" in
> the
> > mapping or cascade="lock, merge" or cascade="lock".
> >
> > 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to