User-153404742 posted
I'm trying to dataBind records from a Linq Query in a gridView control. I have a gridview inside another gridview for one of the columns. Data displays correctly if ALL the columns are Distinct, but I need Distinct records on ALL but one of the
columsn, which is the sub gridview within the main one. I don't know how to work out LINQ query for this. I have the following:
Dim Activities = (From a In db.Activities _
Join b In db.Activities_Attendees _
On a.ActivityID Equals b.ActivityID _
Where (a.CreatedBy = CType(Session("CID"), Integer) And (a.ActivityTime <> 0.0) And _
(a.Date >= projyear And (a.Date <= DateAdd(DateInterval.Day, -1, DateAdd(DateInterval.Year, 1, projyear))))) _
Select a.ActivityID, a.Type, a.ActivityTime, a.Date, a.CreatedBy, a.Comments, b.SignedDate).Distinct
activitiesGridView.DataSource = Activities.ToList()
activitiesGridView.DataBind()
What is happening is that the b.SignedDate can be null or have a date. If there are two records for the same activity, where one record has a null SignedDate and the other has a date, that record shows up twice....however, I only want the record to
show up once. So I need to get distinct on all the columns of "a" table group but not on b.SignedDate. I know I have to use group by but I'm not sure how to go about doing this....thanks for any help.