I have a Linq query that fetches data from database. The problem is I am using “any” to find out If the user has a role which is in api role table. The query is below and it is working with dummy data; but whenever I run the query against to database i receive Local sequence cannot be used in LINQ to SQL implementations of query operators except the Contains operator.
_apiRepository.GetQueryable<ApiInstance>()
.SelectMany(apiInstance => apiInstance.ApiInstanceRoles)
.Where(apiInstanceRole =>
CurrentUser.UsersInRoles.Any(cr => cr.RoleId == apiInstanceRole.RoleId))
Try rewriting the query with
Contains, like this: