带有视图的城堡ActiveRecord错误:生成密钥的NHibernate.PropertyNotFoundException [英] Castle ActiveRecord Error With View: NHibernate.PropertyNotFoundException for generated key
问题描述
我正在使用ActiveRecord映射视图,这意味着我需要一个主键.我没有一个,因此我正在使用ROW_NUMBER()在视图定义中创建一个以放置系统.但是,我似乎不知道如何正确映射它.我得到了:
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:
在类"blah_blah"中找不到字段"stupidID" NHibernate.PropertyNotFoundException:在类"blah_blah"中找不到字段"stupidID"
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?
推荐答案
NosetterLowercaseUnderscore
表示按照惯例使用前缀"_",并且它是小写字母,因此应将字段命名为_stupidid
而不是stupidID
.
NosetterLowercaseUnderscore
means that by convention a prefix '_' is used and it's lowercase, so the field should be called _stupidid
instead of stupidID
.
此外,PK不应为可为空的类型.我会使用long
而不是long?
Also, the PK shouldn't be a nullable type. I'd use long
instead of long?
这篇关于带有视图的城堡ActiveRecord错误:生成密钥的NHibernate.PropertyNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!