问题
I'm mapping a view using ActiveRecord, which means I need a primary key. I don't have one, so I'm using ROW_NUMBER() to create one in the view definition to placate the system. However, I don't seem to know how to map it properly. I'm getting:
Could not find field 'stupidID' in class 'blah_blah' NHibernate.PropertyNotFoundException: Could not find field 'stupidID' in class 'blah_blah'
My mapping looks like this. There is no
public long? stupidID;
[PrimaryKey("StupidId", Access = PropertyAccess.NosetterLowercaseUnderscore)]
public long? StupidId
{
get { return stupidID; }
}
Can anyone see what I'm missing?
回答1:
NosetterLowercaseUnderscore
means that by convention a prefix '_' is used and it's lowercase, so the field should be called _stupidid
instead of stupidID
.
Also, the PK shouldn't be a nullable type. I'd use long
instead of long?
来源:https://stackoverflow.com/questions/7405871/castle-activerecord-error-with-view-nhibernate-propertynotfoundexception-for-ge