Click here to Skip to main content
15,889,863 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear sir,

Error Occured in Linq getting Between dates when I Write a Query, How to solve this problem?

My Example is,
Passing values : StartDate, EndDate
C#
var myExample=(from ex in db.Office
               where ex.startdate<=StartDate && ex.enddate>=EndDate
select 
{
NoOfBirthdays=((from i in db.Employee where (i.id<100 && i.dob<=StartDate && i.dob>=EndDate)
select i.id).Count())
});

this is my example Query,

This Query executed with error/Duplicate records. because inside where condition only check [i.id<100] but not checking [i.dob<=StartDate && i.dob>=EndDate]between date Condition.

How to solve this problem?

By mohan reply me.
Posted
Updated 9-Jan-12 5:13am
v3

I am not really sure about what you are trying to archive...
shouldn't the "between" comparison be:
C#
i.dob >= StartDate && i.dob <= EndDate

The way you are doing it you search for entries where the dateofbirth is smaller/equal than the StartDate and greater/equal then the EndDate, so it is actually not between both dates.

Sorry if I misunderstood the question.
cheers
 
Share this answer
 
i have solved this Query myself

Error: inside where condition alias name passed wrongly
i ll put outside query alias so i solve my problem

i ll meet next Question with valuable one

by from mohan
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900