Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
340 views
in Technique[技术] by (71.8m points)

c# - Query Unmapped Columns in 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

and we have an object

public class Customer
{
    public virtual int CustomerId {get;set;}
    public virtual string name {get;set;}
}

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...