The expression that is thrown is:
System.NotSupportedException: 'Unable to create a constant value of type 'CantShowYouThis'. Only primitive types or enumeration types are supported in this context.'
Query that causes an error
context.tableA.RemoveRange(context.tableA.Where(conflict => listOfCantShowYouThis.Select(r =>
r.Id).Contains(conflict.RequestId)));
Solution:
var list = listOfCantShowYouThis.Select(r => r.Id);
context.tableA.RemoveRange(context.tableA.Where(conflict => list.Contains(conflict.RequestId)));
This code is taken from the codebase I'm working with, so I've had to remove the names of classes and such just to stay on the safe side.
From googling a bit I think it is related to the mixing of in-memory data and database data which EF / LINQ-to-entity doesn't like. I might be wrong, but even if I'm not, it is still a very shallow understanding of what is going on. I'd like to understand why my fix works. I know that doing Select won't really do much until it is actually used (by calling ToList() or some other method), because of deferred execution so it strange to me that moving it like this solves the problem.
CantShowYouThis
the type oflistOfObject
and if so you should change it toList<CantShowThis>
otherwise it's hard to guess at what your actual error is