The reason why you should be checking whether or not the object still
exists is for optimistic concurrency reasons, you really have no clue
how long the page has been open. Apart from that it seems natural to
me to first refresh, lock or whatever strategy you prefer to check for
database state. Even you could add a version property or something to
minimalize database strain.

On 21 jan, 10:07, "[email protected]"
<[email protected]> wrote:
> Been using NHibernate for a while now and since i come from the
> wonderful world of classic ASP I wonder whats considered the best
> practice when handling deletes and updates.
>
> I've recently been looking through some frameworks, like S#arp, and
> i've seen that when updating or deleting entites the default way is to
> load them, apply any changes and than update or delete the entity.
>
> Since has I've stated I'm from the world of ASP this seems odd and
> adds a bit of extra strain on the database server.
>
> Up until now when I've deleted objects by just setting the Id of the
> object and done a Session.Delete(obj);
> For this to work I've used Bill McCafferty 
> articlehttp://www.codeproject.com/KB/architecture/NHibernateBestPractices.aspx
> and used the interface IHasAssignedId<T>, which of course always has
> seemed like a hack to me.
>
> Another thing thats come to mind is the scenario when we use a <many-
> to-one> mapping.
> Lets say we create a new item. This item should be placed in a
> category. When i create the item, should I do it like this:
>
> var item = View.GetItem();
> item.Category = CategoryRepository.GetById(View.CategoryId);
>   or
> item.Category = new Category() { AssignedId = >View.CategoryId }; //To
> avoid database call
>
> How do you handle these scenarios? Should i load up objects and than
> delete or update them? What is considered the best practice?
--~--~---------~--~----~------------~-------~--~----~
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