Hi all,
I have some issue with linq statement. here is my table, named Tblactivity
activityid bigint
studentid bigint
activitydate datetime
description nvarchar(Max)
status bit
i populate Tblactivity with data. such as
activityid | studentid | activitydate | description | status
1 | 1 | 2012-08-15 00:30:00 | descA | A
2 | 3 | 2012-08-16 12:30:00 | descAA | A
3 | 2 | 2012-08-16 13:15:12 | descB | B
4 | 3 | 2012-09-02 10:20:11 | descS | A
5 | 3 | 2012-09-02 11:00:00 | descS | A
6 | 4 | 2012-09-02 14:00:00 | descAA | S
so i develop linq to get detail information of student id = 3. here is my linq code
public List<Tblactivity> getStudents(long studentid, string status)
{
studentdatacontext db=new studentdatacontext;
try
{
List<Tblactivity> BG = (from o in db.Tblactivities
orderby o.activitydate descending where o.studentid == studentid &&
o.activitydate.Value.Month <= DateTime.Now.Month &&
o.activitydate.Value.Month >= DateTime.Now.Date.AddMonths(-1)&&
o.status == status select o).ToList();
return BG;
}
catch (Exception e)
{
throw e;
}
}
so i got all of the records according to student id = 3.but i want only one record when the activitydate is same (the latest record).
i read some article they suggest me to use MAX(). but i don't know how to develop to suit with the above function. pls suggest me.
Thanks,
df