This problem is normally caused by a failure in type inference from in the expression provided to the Where statement. As was mentioned in the comments above it is 100% caused by the assignment operator in the lambda returning an int
instead of a bool
.
To be clear - where you have
var result = db.Set.Where(x => x.Id = num).Select(whatever);
You should have
var result = db.Set.Where(x => x.Id == num).Select(whatever);
Another good (and more common) example of this is something like this
public class Elem
{
public bool IsSomething {get;set;}
public bool? IsSomethingElse {get;set;}
}
Then if you do the following query, which looks very reasonable at fist glance, it will fail to compile with the rather puzzling error of "abiguous invocation"
IQueryable<Elem> queryable = GetQueryable();
var result = queryable.Where(e => e.IsSomething && e.IsSomethingElse).ToList();
If you weren't writing this statement inside a lambda then you would get a more meaningful error of
"Cannot apply operator '&&' to operands of type 'System.Nullable<bool>' and 'bool'"
Which would immediately tell you that you are failing to return a boolean.
db.Set
? – Resnatron=
to equality==
:) – Dagdb
is aDbContext
,Set
should have a generic type parameter. – Comprehensible