s.k.paul s.k.paul - 1 year ago 88
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 Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download