Fluent Nibernate在映射中放置了一个where子句 [英] Fluent Nibernate putting a where clause in the mapping

查看:128
本文介绍了Fluent Nibernate在映射中放置了一个where子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个对象的父母和孩子的名单。在我父母的流利的nhibernate映射中,我想加载孩子的列表。但是我希望这是有条件的,子表中的一列被称为IsDeleted,我只想返回IsDeleted为false的子代。 / p>

是否可以设置映射来执行此操作?如果没有,可以在标准的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆