NHibernate property formula filter

匿名 (未验证) 提交于 2019-12-03 08:46:08

问题:

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> 

I'm trying to load entity through spring with:

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

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?

Many thanks!

回答1:

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...



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