tags:

views:

42

answers:

1

I'm using a Linq Query to populate a GridView.

Then I set it to the Datasource.

In the sorting event, I'd like to retrieve the the anonymous type that the query generates and find the members name.

Is it possible to do so ?

Here's an exemple of the query

var q = from inboundCall in dc.GetTable<InboundCall>()
join employee in dc.GetTable<Employee>() on inboundCall.EmployeeID equals employee.ID
join code in dc.GetTable<Code>() on inboundCall.CodeID equals code.ID
join site in dc.GetTable<Site>() on inboundCall.SiteID equals site.ID
where inboundCall.IsSuccess == true
                    select new
                               {
                                   EmployeeNumber = employee.Number,
                                   EmployeeName = employee.Name,
                                   CallerID = inboundCall.CallerID,
                                   SiteName = site.Name,
                                   CallDate = inboundCall.CallDate,
                                   CodeName = code.Name
                               };

And then

gridData.DataSource = q;

What can I do in the sorting event to retieve the Anonymous type and do something like that

employeeList.Sort((x, y) => ((Int32)x.GetType().GetProperty(e.SortExpression).GetValue(x, null)).CompareTo((Int32)y.GetType().GetProperty(e.SortExpression).GetValue(y, null)) * sortValue);
A: 

You could do this with reflection, or you could use the dynamic LINQ library to add the OrderBy clause.

Or, a better option may be to create an actual class / struct that represents the data you will be retrieving.

ck
Yes, I already tought about creating a custom class, but how would I do it with reflection ?Any thing you can point me to do it ? I can already do it with a grid binded on a table, using the first element on the list. But I don't know which casting I should do to be able to retrieve that information.Any idea ?
Patrick Parent