NHibernate.Mapping.Attributes.Filter [英] NHibernate.Mapping.Attributes.Filter

查看:201
本文介绍了NHibernate.Mapping.Attributes.Filter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我映射使用NHibernate与NHibernate.Mapping.Attributes库我的数据库表和我被困获得属性筛选工作。

I'm mapping my database tables using NHibernate with NHibernate.Mapping.Attributes library and I got stuck to get the Filter attributes to work.

假设有一组B类对象,所以A类,我有以下内容:

Suppose a class A that has a set of objects of class B. So, I have, the following:

[NHibernate.Mapping.Attributes.Set(0, Inverse = true, Lazy = NHibernate.Mapping.Attributes.CollectionLazy.False)]
[NHibernate.Mapping.Attributes.Key(1, Column = "ClassAId")]
[NHibernate.Mapping.Attributes.OneToMany(2, Class = "ClassB, Assembly")]

    public virtual ISet<ClassB> ClassBs { get; set; }

我想在此集合创建一个过滤器,使满足给定的标准只有B类对象,如状态= 1。

I want to create a filter on this collection to bring only class B objects that satisfy a given criteria, such as Status = 1.

如何创建这样的过滤器?

How can I create such Filter?

推荐答案

其中,设置映射的参数应能为您排忧解难。每个文件的参数的地方:

The where parameter of the Set mapping should be able help you out. Per the documentation the where parameter:

其中:(可选)指定任意
  SQL WHERE中使用条件时,
  检索或去除收集
  (如果收集应有用
  仅含有可用的一个子集
  数据)

where: (optional) specify an arbitrary SQL WHERE condition to be used when retrieving or removing the collection (useful if the collection should contain only a subset of the available data)

所以要上的状态过滤(假定状态是在映射为ClassB的表中的SQL列 - 尽管这列不具有在NHibernate的映射映射)

So to filter on Status (assuming Status is a SQL column in the table mapped for ClassB - though this column does not have to be mapped in the NHibernate mapping).

[NHibernate.Mapping.Attributes.Set(0,...., Where = "Status = 1", .....)]
...
public virtual ISet<ClassB> ClassBs { get; set; }

这篇关于NHibernate.Mapping.Attributes.Filter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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