在[Fluent] Nhibrenate中的继承类上调用存储程序,而无需歧视器
我有一个有效的工程,并带有一些继承的表,
class Base { int BaseId }
class Derived : Base {}
class Derived2 : Base {}
class BaseMap : ClassMap<Base> { ID BaseId ); }
class DerivedMap : SubclassMap<Derived> { Id( BaseId ); }
class DerivedMap2 : SubclassMap<Derived2> {Id( BaseId ); }
这些表没有专用的“歧视器”列,Nhibernate只是将其弄清楚。
我注意到它运行的SQL查询,即使我专门请求base
entity,它将加入所有子类,添加case
语句,带有命名<代码> clazz ,并使用它返回带有可用的扩展对象的代理(因此 it 知道是否存在'derived2',只会给我这个)。这一切都很好...
问题
我有一个现有的存储过程,该过程从base
中返回记录。我正在尝试通过createSqlquery
喜欢这样的来调用它:
Session.CreateSQLQuery( "exec SP_GetAllFromBase" )
.AddEntity( nameof( Base ) )
.List<Base>();
但是,当我尝试将其映射为base
的实体类型时,我会得到indexoutofrange
异常,因为NHibernate试图在返回的结果集中找到clazz
属性(就像它添加到所有自己的查询中一样...)。但是,存储的过程只是从base
返回行,而不是将特殊案例语句添加到最后。
我有没有办法告诉createSqlquery
具体需要返回base
实例而不是derived
?
I have a working Fluent project with some inherited tables
class Base { int BaseId }
class Derived : Base {}
class Derived2 : Base {}
class BaseMap : ClassMap<Base> { ID BaseId ); }
class DerivedMap : SubclassMap<Derived> { Id( BaseId ); }
class DerivedMap2 : SubclassMap<Derived2> {Id( BaseId ); }
These tables do not have a dedicated "discriminator" column, NHibernate just figures it out.
I've noticed that the SQL queries it runs, even if I specifically request a Base
entity, it will join to all subclasses, add a CASE
statement with a parameter named clazz
, and use that to return a proxy with the extended objects available (so it knows if there is a 'derived2' in existence and will just give me that). This all works fine...
Problem
I have an existing stored procedure that returns records from Base
. I'm trying to call this via CreateSqlQuery
like so:
Session.CreateSQLQuery( "exec SP_GetAllFromBase" )
.AddEntity( nameof( Base ) )
.List<Base>();
But when I try to map it an entity type of Base
, I get an IndexOutOfRange
exception as NHibernate tries to find a clazz
property in the returned result set (just like it adds onto all its own queries...). But the stored procedure is just returning rows from Base
and not adding a special case statement to the end.
Is there is way I can tell CreateSqlQuery
that it specifically needs to return a Base
instance and not Derived
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论