2
Answers

datediff with case statement in select query linq

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)