Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fluent Nibernate putting a where clause in the mapping

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 called "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

like image 264
lancscoder Avatar asked Feb 23 '10 15:02

lancscoder


1 Answers

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.

like image 59
Jamie Ide Avatar answered Nov 09 '22 22:11

Jamie Ide