I used dynamic linq to generate search results. The very last call is .Select("UserID"), which ultimately returns an IQueryable (non-generic interface).
Now, that represents my list of users who meet search criteria.
Next, I'm trying to join those results with the original Users table so I can then join in the rest of the info associated with each user.
When I try to do this:
IQueryable<Users> users = /*assume valid instance acquired*/
/*matchingUsers is a valid IQueryable instance returned by a dynamic linq query*/
var results = users
.Join( matchingUsers, u => u.ID, m => m.UserID, (u, m) => u )
That fails trying to access m.UserID, because the type of the IQueryable is unknown. The type is accessible as a Type instance on the IQueryable via the ElementType property, but I don't know how I can use it in this situation.
I've also tried the following:
private class UserIDList { public Guid UserID { get; set; } }
filteredUsersDynamicLinqQuery
.Select("new MyNamespace.UserIDList(UserID)")
but the new operator can't seem to handle specific type names. I saw another post suggesting it could, so maybe the syntax is just wrong, but it may just be a custom feature.
I've tried :
var results = users
.Join( matchingUsers.Cast<dynamic>, u => u.ID, m => m.UserID, (u, m) => u )
It's highlighted by the compiler with error: "An expression tree may not contain a dynamic operation."
I've tried:
var results = users
.Join( matchingUsers.Cast<UserIDList>(), u => u.ID, (UserIDList m) => m.UserID, (u, m) => u )
But that gives the runtime error: "Additional information: Unable to cast the type 'DynamicClass3' to type 'MyNamespace+UserIDList'. LINQ to Entities only supports casting EDM primitive or enumeration types." See also: IQueryable to List