Fluent Nibernate putting a where clause in the mapping

守給你的承諾、 提交于 2019-12-09 12:59:08

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/2319244/fluent-nibernate-putting-a-where-clause-in-the-mapping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!