Rod*_*ira 6 c# nhibernate firebird fluent-nhibernate
我有这门课
public class Bill : EntityBase
{
public virtual decimal Value { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
在下面的映射中,我使用a中的过程填充'Value'的值 Formula()
public class MapBill : ClassMap<Bill>
{
public MapBill()
{
Table("cabrec");
Map(m => m.Value)
.Formula(
"(select t.VALOR_IND from ret_vlorind(1,1,cast('02/06/1993' as Date)) as t)")
.CustomType(typeof(decimal));
}
}
Run Code Online (Sandbox Code Playgroud)
但它在执行时返回错误:
{"Dynamic SQL Error\r\nSQL error code = -104\r\nToken unknown - line 1, column 279\r\n."}
Run Code Online (Sandbox Code Playgroud)
有没有办法在流利的nhibernate中使用程序?
公式映射表达式稍后由NHibernate转换为这样的语句
// source in code
(select t.VALOR_IND from ret_vlorind(1,1,cast('02/06/1993' as Date)) as t)
// sent SQL statement
(select t.VALOR_IND from ret_vlorind(1,1,cast('02/06/1993' as Date)) as this_.t)
Run Code Online (Sandbox Code Playgroud)
这个_.在地方注入前缀,NHibernate认为它应该正确使用MAIN表别名.
这不是我们想要的......而且我找到的唯一方法是介绍我们自己的Dialect(我正在使用SQL Server)并定义一些"CONSTANTS"来对待 - 我不需要前缀
public class CustomMsSql2012Dialect : MsSql2012Dialect
{
public CustomMsSql2012Dialect()
{
RegisterKeyword("my_table_alias");
...
Run Code Online (Sandbox Code Playgroud)
这必须用于配置
<property name="dialect">MyNamespace.CustomMsSql2012Dialect,MyLib</property>
Run Code Online (Sandbox Code Playgroud)
最后,我们必须调整我们的陈述
// wrong t is not known keyword.. would be prefixed
(select t.VALOR_IND from ret_vlorind(1,1,cast('02/06/1993' as Date)) as t)
// into this
(select my_table_alias.VALOR_IND from ret_vlorind(1,1,cast('02/06/1993' as Date)) as my_table_alias)
Run Code Online (Sandbox Code Playgroud)
注意:关键字,我的经验,必须只是小写