在 NHibernate 中查询未映射的列 [英] Query Unmapped Columns in NHibernate
问题描述
我有一个使用 NHibernate 映射到表的类.问题是只有部分属性映射到表中的列.这很好,因为我们用于显示的唯一列是映射的,但是我想知道是否有任何方法可以查询表中未映射到我的类中的属性的其他列.
I have a class that is mapped to a table using NHibernate. The problem is that only some of the properties are mapped to columns in the table. This is fine because the only columns we use for display are mapped, however I was wondering if there is any way to query against other columns in the table that aren't mapped to properties in my class.
例如,我们有一个包含以下列的表格:
For example we have a table with the following columns:
Customer
-----------
CustomerId
Name
DateCreated
我们有一个对象
public class Customer
{
public virtual int CustomerId {get;set;}
public virtual string name {get;set;}
}
和 name
和 customerId
被映射,但是 DateCreated
不是,因为我们从来没有在任何地方显示它.我们想在 Customer
表中查询在特定日期创建的客户.有没有办法在不映射DateCreated
的情况下做到这一点?此外,最好使用标准 API 来执行此操作.
and name
and customerId
are mapped however DateCreated
is not because we never display it anywhere. We would like to query the Customer
table for customers that were created by a certain date. Is there any way to do this without mapping the DateCreated
? Also it would be preferable to do this using the criteria API.
推荐答案
Ayende Rahien 发表了一篇文章,描述了在映射中指定 access="noop"
以指定仅查询属性.参见 NHibernate – 只查询属性.我自己没试过.
Ayende Rahien posted an article which describes specifying access="noop"
in the mapping to specify query-only properties. See NHibernate – query only properties. I have not tried this myself.
这篇关于在 NHibernate 中查询未映射的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!