0

I need to convert a query similar to this.
But I need to call a native SQL Server functions (conversion, system, ...).
How can I call them using Entity Framework?
Below is an example of the query.

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
Community
  • 1
  • 1
Sr Julien
  • 494
  • 1
  • 8
  • 27
  • See [DbFunctions](https://msdn.microsoft.com/en-us/library/system.data.entity.dbfunctions(v=vs.113).aspx) – Igor Oct 03 '16 at 15:38

1 Answers1

1

For Case When ... use

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

For IsNull .. use

tbf.qt_width ?? 0,

In addition to DbFunctions mentioned by Igor, there is also SqlFunctions

imaCoden
  • 479
  • 3
  • 8