NHibernate.Mapping.Attributes.Filter(NHibernate.Mapping.Attributes.Filter)

系统教程 行业动态 更新时间:2024-06-14 17:04:02
NHibernate.Mapping.Attributes.Filter(NHibernate.Mapping.Attributes.Filter)

我正在使用NHibernate和NHibernate.Mapping.Attributes库来映射我的数据库表,并且我坚持让Filter属性起作用。

假设一个A类有一组B类对象。所以我有以下几点:

[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类对象,例如Status = 1。

我该如何创建这样的过滤器?

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

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; }

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?

最满意答案

Set映射的where参数应该可以帮助你。 根据文档where参数:

其中:(可选)指定在检索或删除集合时要使用的任意SQL WHERE条件(如果集合应仅包含可用数据的子集,则非常有用)

因此要过滤状态(假设Status是为ClassB映射的表中的SQL列 - 尽管此列不必在NHibernate映射中映射)。

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

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

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)

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; }

更多推荐

Mapping,NHibernate,Attributes,电脑培训,计算机培训,IT培训"/> <meta name="

本文发布于:2023-04-24 20:54:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/bb871512c59114920db9a2152ff260dd.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Mapping   NHibernate   Filter   Attributes

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!