Fluent Nibernate在映射中放置了一个where子句 [英] Fluent Nibernate putting a where clause in the mapping
问题描述
是否可以设置映射来执行此操作?如果没有,可以在标准的nhibernate中做到这一点吗?
谢谢
HasMany(x => x.Children).Where(IsDeleted = 0);
Where约束应该使用SQL语法而不是HQL。对于允许软删除的表,可能更容易映射过滤已删除记录的视图。
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
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.
这篇关于Fluent Nibernate在映射中放置了一个where子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!