Repository navigation
Closed
Milestone
Description
Database: MSSQL
EntityFramework: Microsoft.EntityFrameworkCore:1.0.0-rc2-20261(aspnetcidev)
Query
ctx.DeviceMsgUps
.Where(dm => dm.Action == 27
&& ctx.UserDeviceMaps
.Where(udp => udp.DeviceId != null).Select(udp => udp.DeviceId).Contains(dm.DeviceId))
.Count()Model
[System.CodeDom.Compiler.GeneratedCodeAttribute("EF.Reverse.POCO.Generator", "2.18.1.0")]
public class DeviceMsgUp
{
public int MessageId { get; set; } // Message_ID (Primary key)
public int DeviceId { get; set; } // Device_ID
public byte Format { get; set; } // Format
public byte Action { get; set; } // Action
public string Data { get; set; } // Data (length: 1000)
public System.DateTime? ExpireTime { get; set; } // Expire_Time
public System.DateTime Update { get; set; } // Update
public byte ResultStatus { get; set; } // Result_Status
public string ResultData { get; set; } // Result_Data (length: 1000)
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("EF.Reverse.POCO.Generator", "2.18.1.0")]
public partial class UserDeviceMap
{
public int UdMapId { get; set; } // UDMap_ID (Primary key)
public int UserId { get; set; } // User_ID
public int? DeviceId { get; set; } // Device_ID
public int? StudentId { get; set; } // Student_ID
public int? ClassId { get; set; } // Class_ID
public string NickName { get; set; } // Nick_Name (length: 20)
public string Image { get; set; } // Image (length: 50)
public bool? Gender { get; set; } // Gender
public System.DateTime? BirthDate { get; set; } // Birth_Date
public System.DateTime? BindDate { get; set; } // Bind_Date
public byte Status { get; set; } // Status
public int Creator { get; set; } // Creator
public System.DateTime Upload { get; set; } // Upload
public int Login { get; set; } // Login
public System.DateTime Update { get; set; } // Update
public string CellPhoneNum { get; set; } // CellPhoneNum (length: 11)
// Reverse navigation
public virtual System.Collections.Generic.ICollection<UserWalkTarget> UserWalkTargets { get; set; } // Many to many mapping
// Foreign keys
public virtual Class Class { get; set; } // FK_User_Device_Map_Class_ID_Class_Class_ID
public virtual Device Device { get; set; } // FK_User_Device_Map_Device_ID_Device_Device_ID
public virtual Role Role { get; set; } // FK_User_Device_Map_User_ID_Role_Role_ID
public virtual Student Student { get; set; } // FK_User_Device_Map_Student_ID_Student_Student_ID
public UserDeviceMap()
{
UserWalkTargets = new System.Collections.Generic.List<UserWalkTarget>();
}
}Error
没有为类型“System.Boolean”和“System.Nullable`1[System.Int32]”定义二进制运算符 AndAlso。
+ System.Linq.Expressions.Expression.AndAlso(System.Linq.Expressions.Expression, System.Linq.Expressions.Expression, System.Reflection.MethodInfo)
+ Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.SqlTranslatingExpressionVisitor.VisitBinary(System.Linq.Expressions.BinaryExpression)
+ System.Linq.Expressions.BinaryExpression.Accept(System.Linq.Expressions.ExpressionVisitor)
+ Remotion.Linq.Parsing.ThrowingExpressionVisitor.Visit(System.Linq.Expressions.Expression)
+ Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.SqlTranslatingExpressionVisitor.Visit(System.Linq.Expressions.Expression)
+ Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitWhereClause(Remotion.Linq.Clauses.WhereClause, Remotion.Linq.QueryModel, int)
+ Remotion.Linq.Clauses.WhereClause.Accept(Remotion.Linq.IQueryModelVisitor, Remotion.Linq.QueryModel, int)
+ Remotion.Linq.QueryModelVisitorBase.VisitBodyClauses(ObservableCollection<Remotion.Linq.Clauses.IBodyClause>, Remotion.Linq.QueryModel)
+ Remotion.Linq.QueryModelVisitorBase.VisitQueryModel(Remotion.Linq.QueryModel)
+ Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitQueryModel(Remotion.Linq.QueryModel)
+ Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitQueryModel(Remotion.Linq.QueryModel)
+ Microsoft.EntityFrameworkCore.Query.Internal.SqlServerQueryModelVisitor.VisitQueryModel(Remotion.Linq.QueryModel)
+ Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateQueryExecutor<TResult>(Remotion.Linq.QueryModel)
+ Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery<TResult>(Remotion.Linq.QueryModel)
+ Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery<TResult>(object, Func<Func<Microsoft.EntityFrameworkCore.Query.QueryContext, TResult>>)
+ Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQuery<TResult>(System.Linq.Expressions.Expression)
+ Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute<TResult>(System.Linq.Expressions.Expression)
+ Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute<TResult>(System.Linq.Expressions.Expression)
+ System.Linq.Queryable.Count<TSource>(IQueryable<TSource>)
Contains Works(Replace .Select(udp => udp.DeviceId) with .Select(udp => udp.DeviceId.Value)
If remove dm => dm.Action == 27 &&, it will failed with another Exception, which is much more easy to recognise.
fail: Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler[1]
An exception occurred in the database while iterating the results of a query.
System.Data.SqlClient.SqlException (0x80131904): 子查询返回的值不止一个。当子查询跟随在 =、!=、<、<=、>、>= 之后,或子查询用作表达式时,这种情况是不允许的。
在 System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
在 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
在 System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
在 System.Data.SqlClient.SqlDataReader.TryHasMoreRows(Boolean& moreRows)
在 System.Data.SqlClient.SqlDataReader.TryReadInternal(Boolean setTimeout, Boolean& more)
在 System.Data.SqlClient.SqlDataReader.Read()
在 Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable.Enumerator.MoveNext()
在 Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.GetResult[TResult](IEnumerable`1 valueBuffers)
在 lambda_method(Closure , QueryContext )
在 Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass19_1`1.<CompileQuery>b__1(QueryContext qc)
ClientConnectionId:f79bebbe-3345-41c1-90f4-3e7fd1c4e36b
Error Number:512,State:1,Class:16
System.Data.SqlClient.SqlException (0x80131904): 子查询返回的值不止一个。当子查询跟随在 =、!=、<、<=、>、>= 之后,或子查询用作表达式时,这种情况是不允许的。
在 System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
在 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
在 System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
在 System.Data.SqlClient.SqlDataReader.TryHasMoreRows(Boolean& moreRows)
在 System.Data.SqlClient.SqlDataReader.TryReadInternal(Boolean setTimeout, Boolean& more)
在 System.Data.SqlClient.SqlDataReader.Read()
在 Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable.Enumerator.MoveNext()
在 Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.GetResult[TResult](IEnumerable`1 valueBuffers)
在 lambda_method(Closure , QueryContext )
在 Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass19_1`1.<CompileQuery>b__1(QueryContext qc)
ClientConnectionId:f79bebbe-3345-41c1-90f4-3e7fd1c4e36b
Error Number:512,State:1,Class:16
System.ArgumentNullException: 值不能为 null。
参数名: source
在 System.Linq.Enumerable.Any[TSource](IEnumerable`1 source)
在 Microsoft.CodeAnalysis.Scripting.Hosting.CommonMemberFilter.IsHiddenMember(MemberInfo info)
在 Microsoft.CodeAnalysis.Scripting.Hosting.CommonMemberFilter.Include(StackFrame frame)
在 Microsoft.CodeAnalysis.Scripting.Hosting.CommonObjectFormatter.FormatException(Exception e)
在 Microsoft.CodeAnalysis.CSharp.Scripting.Hosting.CSharpObjectFormatter.FormatException(Exception e)
在 Microsoft.CodeAnalysis.Interactive.InteractiveHost.Service.<>c__DisplayClass42_0.<<ExecuteOnUIThread>b__0>d.MoveNext()
--- 引发异常的上一位置中堆栈跟踪的末尾 ---
在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
在 Microsoft.CodeAnalysis.Interactive.InteractiveHost.Service.<ExecuteOnUIThread>d__42.MoveNext()
--- 引发异常的上一位置中堆栈跟踪的末尾 ---
在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
在 Microsoft.CodeAnalysis.Interactive.InteractiveHost.Service.<ExecuteAsync>d__30.MoveNext()
Activity
mikary commentedon Apr 8, 2016
I attempted to reproduce the issue using the latest packages
Microsoft.EntityFrameworkCore:1.0.0-rc3-20498(aspnetcidev), but it does not throw the exception.@yyjdelete can you confirm if this is still failing for you? If so, could you provide additional information about how your model is created and the specific data that causes the exception to be thrown?
Here is the code that I used to attempt to reproduce the issue:
yyjdelete commentedon Apr 9, 2016
@mikary
Maybe you mix up #4860 with #4858, they are 2 independent issues.
The same with
1.0.0-rc3-20498, Test code for two, tradition csproj with DotNet461 is used,packages.config
mikary commentedon Apr 12, 2016
There appears to be a bug in the translation of the
Containsof the provided query:When calling
SqlTranslatingExpressionVisitor.VisitBinaryon the firstWhere, it attempts to create an expression with the left equal to a boolean expression fordm => dm.Action == 27and the right equal to a nullable int expression equal to(SELECT [udp].[DeviceId] FROM [UserDeviceMaps] AS [udp] WHERE [udp].[DeviceId] IS NOT NULL). (Perhaps attempting to translate the right into aWHERE EXISTS)mikary commentedon Apr 12, 2016
clearing milestone for triage
[-]Confused exception with when Contains<int?> is used in where with other expression[/-][+]Query: Contains in AndAlso translates to non-boolean value[/+]mikary commentedon Apr 26, 2016
Closing this issue as it appears to be a duplicate of #3705, Exception thrown for Where with Contains.