开发者

Fluent Nibernate putting a where clause in the mapping

开发者 https://www.devze.com 2022-12-21 12:55 出处:网络
I\'ve got two objects a parent and a child list. In my fluent nhibernate mapping for the parent I want to load the list of the children.

I've got two objects a parent and a child list. In my fluent nhibernate mapping for the parent I want to load the list of the children.

However I want this to be conditional, a column in the child table is calle开发者_如何学JAVAd "IsDeleted" and I only want to return the children where "IsDeleted" is false.

Is it possible to set up a mapping to do this? If not is it possible to do it in just standard nhibernate?

Thanks


Yes, you can use a Where constraint in Fluent NHibernate to map this. Somehting like:

HasMany(x => x.Children).Where("IsDeleted = 0");

The Where constraint should use SQL syntax not HQL. For tables that allow soft deletes it's probably easier to map a view that filters the deleted records out.

0

精彩评论

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