Given: EF Core 1.0.1 and the following classes:
public class User { public int UserId {get;set;} public string Login {get;set;} public string Password {get;set;} } public class DataContext:DbContext { public DbSet<User> Users { get; set; } } in the following code
Datacontext dbcon = new DataContext(); var users = from p in dbcon.Users where p.Login=="login1" && p.Password=="pass1" select p; int number = users.Count(); an error occurs
InvalidOperationException: The "op_Equality" method.
why it happens? what should be done? complete exception description:
System.InvalidOperationException: "Op_Equality". at System.Linq.Expressions.Expression.GetMethodBasedBinaryOperator (ExpressionType binaryType, Expression left, Expression right, MethodInfo method, Boolean liftToNull) at System.Linq.Express_Enthal.Expression.Equal (Expression left, Expression right, Boolean liftToNull, method, Expression.Equal System.Linq.Expressions.Expression.MakeBinary (ExpressionType binaryType, Expression left, Expression of the right, Boolean liftToNull, MethodInfo method, LambdaExpression conversion) at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.NavigationRewritExEx of ours, 5888, 58, 17, 58, 58. Graphics.Query.ExpressionVisitors. .Expressions.BinaryExpression.Accept (ExpressionVisitor visitor) at System.Linq.Expressions.ExpressionVisitor.Visit (Expression node) at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.NavigationRewritingExpressionVisitor.VisitBinary (Insthedurant.Internal.NavigationRewritingExpressionVisitor.VisitBinary (Inventory.Internal.NavigationRewritingExpressionVisitor.VisitBinary (Supplicat.Internal.NavigationRewritingExpressionVisitor.VisitBinary (Incremental ReplicationVis.Internal.NavigationRewritingExpression node)) .Accept (ExpressionVisitor visitor) at System.Linq.Expressions.Expres sionVisitor.com (Expression)
2 transformation) at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.NavigationRewritingExpressionVisitor.NavigationRewritingQueryModelVisitor.VisitWhereClause(WhereClause whereClause, QueryModel queryModel, Int32 index) at Remotion.Linq.QueryModelVisitorBase.VisitBodyClauses(ObservableCollection1 bodyClauses, queryModel queryModel) at Remotion.Linq.QueryModelVisitorBase.VisitQueryModel ( queryModel queryModel) at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.NavigationRewritingExpressionVisitor.Rewrite (queryModel queryModel, queryModel parentQueryModel) at Microsoft. Entity's a Expression query inodetyprovider1.<CompileQuery>b__0() at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func1 compiler) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute [TResult] (Expression query) at System.Linq.Queryable.Count [TSource] (IQueryable`1 source) at SolidCRMCore.Startup . <> c. <b__2_0> d.MoveNext () in C: \ Users \ documents \ visual studio 2017 \ Projects \ SolidCRMCore \ SolidCRMCore \ Startup.cs: line 78 --- exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (Task task) at Microsoft.AspNetCore.Builder.Extensions.MapMiddelow.AnDebuggerNotification (Task task) at Microsoft.AspNetCore.Builder.Extensions.MapMddelow.AnDebuggerNotification (Task Task) - End of stack trace from previous loc ation where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (Task task) at Microsoft.AspNetCore.Diagn ..DeveloperExceptionPraframemad.Me.Mo.MoTe.MapToMeTeMeTeMeTeMeTeMeTeMeTeMeTeMeTeMeoMeToMetoramamak.
var users = db.Users.Where(x=>x.Login == "login1" && x.Password == "pass1").ToList();IMHO, of course, but lambda syntax is easier to read in some cases - Bald