Reputation:
My Table like this.
name date phonenumber
venky 25-06-2013 123123123
vasud 27-06-2013 2423727384
sdfds 14-06-2013 12312332132
If user want to see june month records then he pass 06 as input parameter how to write linq to sql query to get june month records as output..
Upvotes: 0
Views: 1326
Reputation: 1504132
Well it sounds like you just want something like:
public IQueryable<Record> GetRecordsForMonth(int month)
{
return new RecordContext().Where(record => record.Date.Month == month);
}
That's assuming your date
field in the database is actually an appropriate datetime
field or something similar. If it's not, then fix your schema.
Alternatively, for dates within a range, you could take two DateTime
values in the method and filter that way:
public IQueryable<Record> GetRecordsForMonth(DateTime minDateInclusive.
DateTime maxDateExclusive)
{
return new RecordContext().Where(record => record.Date >= minDateInclusive
&& record.Date < maxDateExclusive);
}
Upvotes: 4