2016-10-03 22 views
0

我需要轉換類似於this的查詢。
但我需要調用一個本地SQL Server函數(​​,system,...)。
如何使用實體框架調用它們?
下面是查詢的一個例子。使用實體框架運行本機T-SQL功能

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 
+0

參見[ DbFunctions](https://msdn.microsoft.com/en-us/library/system.data.entity.dbfunctions(v = vs.113)的.aspx) – Igor

回答

1

對於情況當......使用

tbri.ds_referencia == null ? tbf.ds_referencia : tbri.ds_referencia, 

對於ISNULL ..使用

tbf.qt_width ?? 0, 

除了由Igor提到DbFunctions,還有SqlFunctions