Castle ActiveRecord Error With View: NHibernate.PropertyNotFoundException for generated key

你说的曾经没有我的故事 提交于 2019-12-12 06:56:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!