开发者

NHibernate optionally cascade a collection

开发者 https://www.devze.com 2023-03-19 01:49 出处:网络
I use asp.net model binding to retrieve objects from the view. The objects retrieved are rarely ever complete as that would require loading the entire object map.

I use asp.net model binding to retrieve objects from the view. The objects retrieved are rarely ever complete as that would require loading the entire object map.

I have a class such as:

class Garage {
    int garageID;
    String name;
    ICollection<Car> cars;
}

Some views do not get sent the list of cars, so null is returned. On those occassions, I do not wish to cascade="all" (that is what everything is set to) as I assume that would delete all of the cars. On other occassions (when the view gets all of the cars and they are all returned to the controll开发者_运维知识库er), I do want all the cars to be updated when the garage is saved.

Does NHibernate offer any mechanism to perform this? I looked into ILifecycle- it seems a bit complicated and a lot of work. I looked into IValidate - it doesn't seem to apply here.


As it turns out - NHibernate does not delete when a reference is removed if you have cascade="all" set.

0

精彩评论

暂无评论...
验证码 换一张
取 消