Manoj Maharana

Manoj Maharana

  • NA
  • 362
  • 128.6k

datediff with case statement in select query linq

Mar 4 2017 6:39 AM

select case statement in linq query.

Here is the query on sql:
  1. select case when DATEDIFF(day,convert(varchar,Min([Order].CreatedOnUtc),101),convert(varchar,Max([Order].CreatedOnUtc),101)) = 0 then  
  2.  Sum([Order].OrderSubtotal)  
  3.  else   
  4.  case when (DATEDIFF(day,convert(varchar,Min([Order].CreatedOnUtc),101),convert(varchar,Max([Order].CreatedOnUtc),101))/30) = 0 then Sum([Order].OrderSubtotal) else  
  5.  Sum([Order].OrderSubtotal)/  
  6.   (DATEDIFF(day,convert(varchar,Min([Order].CreatedOnUtc),101),convert(varchar,Max([Order].CreatedOnUtc),101))/30)  
  7.  end   
  8.  end as 'Account Value' from [orderwhere And Account.ID = @Act_ID   

I am trying the code here:

  1. var query = _orderRepository.Table;  
  2.        query = query.Where(o => o.AccountId == accountId);  

In query i am getting my value.

After query statement what should i write?? how do i write for case statement using linq???

 
 

Answers (2)