使用实体框架运行本机 T-SQL 函数
Posted
技术标签:
【中文标题】使用实体框架运行本机 T-SQL 函数【英文标题】:Run native T-SQL function with Entity Framework 【发布时间】:2017-02-11 14:37:26 【问题描述】:我需要转换类似于this 的查询。 但我需要调用本机 SQL Server 函数(conversion、system、...)。 如何使用实体框架调用它们? 下面是一个查询示例。
select
tbf.nr_list, tbf.cd_lne, tbf.nr_seq, tbf.cd_ref,
case
when tbri.ds_referencia IS null
then tbf.ds_referencia
else tbri.ds_referencia
end as Ds_Ref,
'' as Ds_Med,
cast(tbf.qt_tec as MONEY) as Qt_Tec,
isnull(tbf.qt_width, 0) as Qt_Width,
isnull(tbf.qt_height, 0) as Qt_Height,
case
when tbra.ds_lne IS null
then 'null'
when right(tbra.ds_lne, 1) = 'X'
then 'x'
when right(tbra.ds_lne, 1) = 'Y'
then 'y'
else tbra.ds_lne
end as Ds_Lne,
tbro.im_pic as Im_Pic,
'' as Cd_Compos1,
0.00 as Vl_Compos1,
rl.dt_end,
'' as Ds_Con,
0.00 as Al_Mar
from
table_from tbf
left join
table_ref_udao tbru on (tbru.nr_list = tbf.nr_list and tbru.cd_lne = tbf.cd_lne)
left join
table_ref_odae tbro on (tbro.nr_list = tbf.nr_list
and tbro.cd_lne = tbf.cd_lne
and tbro.nr_seq = 1)
left join
table_ref_adeo tbra on (tbra.nr_list = tbf.nr_list and tbra.cd_lne = tbf.cd_lne)
left join
table_ref_idio tbri on (tbri.nr_list = tbf.nr_list
and tbri.cd_lne = tbf.cd_lne
and tbri.nr_seq = tbf.nr_seq
and tbri.cd_ref = tbf.cd_ref
and tbri.cd_idi = tbf.cd_idi)
left join
rom_lista rl on(tbru.nr_list = rl.nr_list)
where
tbf.nr_list = '59846'
order by
tbru.ds_lne, tbf.nr_seq
【问题讨论】:
见DbFunctions 【参考方案1】:适用于……使用情况
tbri.ds_referencia == null ? tbf.ds_referencia : tbri.ds_referencia,
对于 IsNull .. 使用
tbf.qt_width ?? 0,
除了伊戈尔提到的DbFunctions,还有SqlFunctions
【讨论】:
以上是关于使用实体框架运行本机 T-SQL 函数的主要内容,如果未能解决你的问题,请参考以下文章