tags:

views:

70

answers:

2

In my application I need to save with NHibernate entities received from WCF service.

Currently I'm using session SaveOrUpdate method for this purpose.

Often we don't need to edit reference properties, so from client I receive object, which has empty collections. But I don't want this empty collection to reflect in database.

Example:

public class Product
{
    public virtual string Name {get;set;}
    public virtual IList<Stores> Stores {get;set;} <--- Stores is empty, but should not be cleared in databse.
}

Thanks, Oksana.

+1  A: 

I'm not sure to understand the question. If you are new to NHibernate have a look at the documentation with the term cascade. This defines what is persisted when an object containing others has to be saved.

jdehaan
+1  A: 

As far as I understand it, you want to update certain properties of the object if it already exsits, and no touch others, is that correct?

Well, basically, in such a case what you'd need to do is this:

  • establish an NHiberate session
  • based on some ID, load the current state of the object from the database
  • update those properties you want to update from the entity you've received in your service call
  • save the modified object back

With this approach, you'll only update those properties you want, and everything else is being left alone.

Does that seem like an approach you can work with?

Marc

marc_s
Thanks for answer, this is what I need! Oksana
Oksana