Reputation: 585
I am generating two lists with int values and select all ids of list one not found in list 2 using linq:
var clerkRole = db.Roles.SingleOrDefault(m => m.Name == "Clerk");
List<ApplicationUser>lstUser = db.Users.Where(x => x.Roles.Select(y => y.RoleId).Contains(clerkRole.Id)).ToList();
List<int> lstUId = lstUser.Select(c => c.Id).ToList();
var alldps = db.Deposits.Select(a => a.UserId).Distinct().ToList();
var clerkNotIn = lstUId.Except(alldps).ToList(); // error here and below
I get the following error:
Error 25 'System.Collections.Generic.List' does not contain a definition for 'Except' and the best extension method overload 'System.Linq.ParallelEnumerable.Except(System.Linq.ParallelQuery, System.Collections.Generic.IEnumerable)' has some invalid arguments
Could you help? thanks
Upvotes: 0
Views: 125
Reputation: 38392
I'm betting you are missing the Linq namespace, add this at the beginning:
using System.Linq;
Also change the var
to be sure that UserId is an int
. This won't have any effect except if UserId is not actually an int
, then you'll get an error indicating UserId is not an int
:
List<int> alldps = db.Deposits.Select(a => a.UserId).Distinct().ToList();
Upvotes: 2