Using nhibernate ,to delete entity with details cascade-delete-orphan,why do I have to get the entity with all details, in order to delete them too?

First, you are going against the principles of Nbernate with this approach. See Ayende's (he's one of the main developers behind it) response to this question in this thread ).

First, you are going against the principles of Nbernate with this approach. See Ayende's (he's one of the main developers behind it) response to this question in this thread) If you are using Nbernate versioning (it looks like you are because of the presence of that Version property) then you will have to get the Order item from the database anyway because it shouldn't let you delete without the correct version number being provided and how would you know it without checking the database? The idea below may work: Create the reference to the Order entity the "N The Correct way to reference a persisted entity without making a call to the database is to use the Session.

Load function. This will return a proxy object of the entity in question which can hydrate itself from the database if needed. You would need to replace this line: Order order = new Order { OrderID = 9, Version =1 }; with Order order = Session.

Load(9); You will have to check with a profiler or logger to see if the Order was actually rehydrated from the database in this instance (which to be honest I think it will).

Considering the versioning: I'm aware of that I need to provide the correct version, and it is not a problem. Because I already holding the id and the version of the entity. But even that, nhibernate consider it not enough.

I tried the Load and as you said it isn't rehydrated from the database . But when you call the delete, it first make a select statement, and then delete one. Well, if this is the only solution, so I will use it.

But still can't understand why just it make a delete statement and use the Id and version as criterion? – Nour Sabouny Oct 28 '10 at 12:46.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions