Reputation: 155
I have a method that receives a string array. I then turn it into a List of ints. Finally I am creating an IQueryable where I want to return results that match the IDs in an associated table.
public myMethod(string[] locationRoleids){
IQueryable<equipment> result = DbContext.equipment.Where(e => !e.deleted);
List<int> locationRoleIdList = locationRoleIds.Select(id => int.Parse(id)).ToList();
result = result.Where(e => locationRoleIdList.Contains(e.eqp_ast_equipment_to_location.Any(el => el.eqp_equipment_location_role_id)));
I'm getting an error on
el.eqp_equipment_location_role_id
stating "Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type"
eqp_equipment_location_role_id is an int and i'm checking if a list of ints contain that number. I don't understand what the problem is.
Thanks in advance.
Upvotes: 0
Views: 5669
Reputation: 3589
Contains
takes a value rather than a lambda. Therefore, e.eqp_ast_equipment_to_location.Any(el => el.eqp_equipment_location_role_id)
isn't a valid item of type int
.
Maybe:
result = result.Where(e => e.eqp_ast_equipment_to_location.Any(el => locationRoleIdList.Contains(el.eqp_equipment_location_role_id)));
is nearer what was intended?
Upvotes: 1