NHibernate属性公式过滤器 [英] NHibernate property formula filter

查看:170
本文介绍了NHibernate属性公式过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类:

I have a following class:

MyClass
public virtual int Id { get; set; }
public virtual int Code { get; set; }
public virtual int Description { get; set; }
public virtual int Name { get; set; }

用以下映射:

with the following mapping:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="TestApplication" assembly="TestApplication">
  <class name="MyClass" table="MyTable">
    <id name="Id" column="id">
      <generator class="native"/>
    </id>

    <property name="Code" column="code"/>
    <property name="Description" column="description"/>
    <property name="Name" formula="(SELECT b.translation FROM translations b WHERE b.translation_id = translation_id AND b.language_id = :TranslationFilter.LanguageId)"/>
  </class>

  <filter-def name="TranslationFilter">
    <filter-param name="LanguageId" type="Int32"/>
  </filter-def>
</hibernate-mapping>

我试图通过spring加载实体:

I'm trying to load entity through spring with:

Session.EnableFilter("TranslationFilter").SetParameter("LanguageId", 1);
return Session.Get<MyClass>(1);

但是我得到了adoexception。我看到(在探查器中)该变量:TranslationFilter.LanguageId不被替换为?并且该参数值不会发送到服务器?

but I'am getting adoexception. I see (in a profiler) that variable :TranslationFilter.LanguageId is not replaced with ? and that parameter value is not send to the server?

这是可能的吗(在公式中有过滤器)以及如何?

Is it this possible (to have filters in formula) and how?

非常感谢!

推荐答案

此功能尚未正式支持。正如oren关于这两种不同特征(公式和过滤器)组合的博客文章应该带着一丝咸味......

This feature is not officially supported. As such oren's blog post about this combination of 2 different features (formulas and filters) should be taken with a grain of salt...

这篇关于NHibernate属性公式过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆