NHibernate performing a delete with Cascade.All causes N+1 deletes -


I have two entities, passwords and passwords in password is a collection of passwords in the password (which are hash with different masks).

When I delete a password, I want to remove all the related password hashes too.

I like this mapping:

  mapping Hasman (x = & gt; x.PasswordHashes) .cascade. All (). Current () .powered by (x => x.password);   

I was expecting two questions to be generated:

  Remove from "passwordHash" where "idpassword" =: p0   

And obviously remove

  from "password" "idpassword" =: p0   

Instead, NHibernate has prepared N + 1 queries in this way Delete: Remove the password from "Password hash": "id password ish" =: p0 (n)

and

  "password"   

How can I make this behavior more optimal?

Edit: Code which deletes:

  session.Delete (password); Session.Flush (); In the current release of NHibernate (3.3), from my research, it seems that    

It is not possible to delete a child collection with a single DELETE statement using functions such as password.hashes.Clear () or session.Delete (password) The NHibernate documentation is mentioned on your domain object, but I can do this work with any combination with any combination and for many organizations, unidirectional or bidirectional A Has been unable to find.

An option is to use the on-deleit = "cascade" which disables cascade functionality in NHibernate and to apply the cascade deletion to the database drop offs. Further information can be found by NH users in the Google Groups discussion.

The other option mentioned by Rippo in the comment section is to use HQL, you will need two statements, so it would be best to wrap them in the transaction, that is, session.BeginTransaction () {session .query ("Delete password hash h from where h .password =: password") .set parameter ("password", password). Index (); Session Delete (password); Transactions. Dialog ();}

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -