s.k.paul s.k.paul - 6 days ago 7
C# Question

Multiple condition in LINQ where clause

I am new to LINQ world. I'm trying to calculate sum as follows-

var newSum = (from c in db.ExecutionDetails
join camp in db.CampaignDetailsPerExecutions
on c.SmsId equals camp.SmsId
where c.AmoCode == 5
&& c.DateTime between date1 and date2 //error
select camp.Poster).Sum();


&&
operator in where clause gives error (red curly underline).

Answer

I hope you are doing this in wrong way, you have to modify the where clause like this:

where c.AmoCode == 5 && 
     (c.DateTime >= date1 && c.DateTime <= date2)

If you want to exclude the upper bounds and lower bounds of dates means remove the = sign from comparison.

Comments