Open Closed

mysql union table query error #5370


User avatar
0
cicna created
  • ABP Framework version: v7.2.2

  • UI type: MVC

  • DB provider: EF Core

  • Tiered (MVC) or Identity Server Separated (Angular): no

  • Exception message and stack trace:

  • InvalidOperationException: The LINQ expression 'ROW_NUMBER() OVER(PARTITION BY a0.Id ORDER BY a0.Id ASC)' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.

  • Steps to reproduce the issue:"

  • 在EfCoreContractRepository.cs中执行这段代码后,报了上面的错误。DB:mysql 5.7.28

  • In EfCoreContractRepository. Cs to execute this code, called the above error. DB:mysql 5.7.28

  • `var dbContext = await GetDbContextAsync();

          var model = (await GetDbSetAsync()).Where(b => b.Id == id)
              .Select(contract => new ContractWithNavigationProperties
              {
                  Contract = contract,
                  Customer = dbContext.Customers.FirstOrDefault(c => c.Id == contract.CustomerId),
                  Department = dbContext.Departments.FirstOrDefault(c => c.Id == contract.DepartmentId),
      			Orders = dbContext.Orders.Where(c => c.ContractId == contract.Id).ToList(),
      			Agent = dbContext.AgentAccounts.FirstOrDefault(c => c.ContractId == contract.Id)
      		}).FirstOrDefault();`
    


7 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    The ROW_NUMBER() OVER seems to belong to SQL Server.

  • User Avatar
    0
    cicna created

    我项目是用abp suite生成的,数据库原本是 SQL Server,工具生成导航属性代码时,用了这种linq写法。 因为abp 7.2.2+sql server 经常性出现以下错误。 我才尝试更改为mysql的 现在无论DB是用sql server,还是mysql,出现的大问题,我都无法解决。 麻烦请指点我解决一下这个问题。 My project is generated with abp suite, the database was originally SQL Server, the tool generated navigation property code, with this linq writing. The following error occurs frequently in abp 7.2.2+sql server. I just tried to change it to mysql Now whether DB is using sql server, or mysql, there are big problems, I can not solve. Please help me solve this problem.

    `[15:11:26 ERR] A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 35 - An internal exception was caught)
    Microsoft.Data.SqlClient.SqlException (0x80131904): A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 35 - An internal exception was caught)
     ---> System.IO.IOException: Unable to read data from the transport connection: Connection reset by peer.
     ---> System.Net.Sockets.SocketException (104): Connection reset by peer
       at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 count)
       --- End of inner exception stack trace ---
       at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 count)
       at System.IO.Stream.Read(Span`1 buffer)
       at System.Net.Sockets.NetworkStream.Read(Span`1 buffer)
       at Microsoft.Data.SqlClient.SNI.SslOverTdsStream.Read(Span`1 buffer)
       at System.Net.Security.SslStream.EnsureFullTlsFrameAsync[TIOAdapter](CancellationToken cancellationToken)
       at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token)
       at System.Net.Security.SslStream.ReadAsyncInternal[TIOAdapter](Memory`1 buffer, CancellationToken cancellationToken)
       at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource&lt;TResult&gt;.GetResult(Int16 token)
       at System.Net.Security.SslStream.Read(Byte[] buffer, Int32 offset, Int32 count)
       at Microsoft.Data.SqlClient.SNI.SNITCPHandle.Receive(SNIPacket& packet, Int32 timeoutInMilliseconds)
       at Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
       at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
       at Microsoft.Data.SqlClient.TdsParserStateObject.ThrowExceptionAndWarning(Boolean callerHasConnectionLock, Boolean asyncClose)
       at Microsoft.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error)
       at Microsoft.Data.SqlClient.TdsParserStateObject.ReadSniSyncOverAsync()
       at Microsoft.Data.SqlClient.TdsParserStateObject.TryReadNetworkPacket()
       at Microsoft.Data.SqlClient.TdsParserStateObject.TryPrepareBuffer()
       at Microsoft.Data.SqlClient.TdsParserStateObject.TryReadByte(Byte& value)
       at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
       at Microsoft.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
       at Microsoft.Data.SqlClient.SqlDataReader.get_MetaData()
       at Microsoft.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
       at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean isAsync, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
       at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry, String method)
       at Microsoft.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)
       at Microsoft.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
       at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject)
       at Microsoft.EntityFrameworkCore.Query.Internal.SplitQueryingEnumerable`1.Enumerator.InitializeReader(Enumerator enumerator)
       at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
       at Microsoft.EntityFrameworkCore.Query.Internal.SplitQueryingEnumerable`1.Enumerator.MoveNext()
       at System.Linq.Enumerable.TryGetSingle[TSource](IEnumerable`1 source, Boolean& found)
       at lambda_method12681(Closure, QueryContext)
       at Ywz.Bms.Contracts.EfCoreContractRepository.GetWithNavigationPropertiesAsync(Guid id, CancellationToken cancellationToken) in /src/src/Ywz.Bms.EntityFrameworkCore/Contracts/EfCoreContractRepository.cs:line 31
       at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
       at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
       at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
       at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
       at Ywz.Bms.Contracts.ContractsAppService.GetWithNavigationPropertiesAsync(Guid id) in /src/src/Ywz.Bms.Application/Contracts/ContractsAppService.cs:line 96
       at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
       at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
       at Volo.Abp.Authorization.AuthorizationInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
       at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
       at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
       at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
       at Volo.Abp.GlobalFeatures.GlobalFeatureInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
       at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
       at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
       at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
       at Volo.Abp.Auditing.AuditingInterceptor.ProceedByLoggingAsync(IAbpMethodInvocation invocation, AbpAuditingOptions options, IAuditingHelper auditingHelper, IAuditLogScope auditLogScope)
       at Volo.Abp.Auditing.AuditingInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
       at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
       at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
       at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
       at Volo.Abp.Validation.ValidationInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
       at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
       at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
       at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
       at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
       at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
       at Ywz.Bms.Web.Pages.Contracts.EditModalModel.OnGetAsync() in /src/src/Ywz.Bms.Web/Pages/Contracts/EditModal.cshtml.cs:line 134
       at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.ExecutorFactory.NonGenericTaskHandlerMethod.Execute(Object receiver, Object[] arguments)
       at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeHandlerMethodAsync()
       at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeNextPageFilterAsync()
       at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.Rethrow(PageHandlerExecutedContext context)
       at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
       at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeInnerFilterAsync()
       at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ExceptionContextSealed context)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
       at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
       at Volo.Abp.AspNetCore.Serilog.AbpSerilogMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
       at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass6_1.<<UseMiddlewareInterface>b__1>d.MoveNext()
    --- End of stack trace from previous location ---
       at Volo.Abp.AspNetCore.Auditing.AbpAuditingMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
    ClientConnectionId:db5dac7f-5fbd-4681-a9d6-629f0dd31509
    [15:11:26 ERR] ---------- Exception Data ----------
    HelpLink.ProdName = Microsoft SQL Server
    HelpLink.EvtSrc = MSSQLServer
    HelpLink.EvtID = 0
    HelpLink.BaseHelpUrl = https://go.microsoft.com/fwlink
    HelpLink.LinkId = 20476`
    
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 35 - An internal exception was caught) Microsoft.Data.SqlClient.SqlException (0x80131904): A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 35 - An internal exception was caught) ---> System.IO.IOException: Unable to read data from the transport connection: Connection reset by peer.

    Please check your connection string and database.

  • User Avatar
    0
    cicna created

    在docker容器的内网ip地址,sql server连接用的字符串是: In the docker container's Intranet ip address, the sql server connection string is: "Default": "Server=172.88.0.102,1433;Database=ProBmsMvc703;User Id=sa;password=A1axI62eslCdlEw;Encrypt=True;TrustServerCertificate=True;"

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    This is not a problem of abp. You can google it.

  • User Avatar
    0
    cicna created

    有个疑问:我的项目数据库已切换为mysql,EF怎么会生成‘ROW_NUMBER() OVER(PARTITION BY a0.Id ORDER BY a0.Id ASC)’呢

    I have a question: My project database has switched to mysql, so how can EF generate 'ROW_NUMBER() OVER(PARTITION BY a0.Id ORDER BY a0.Id ASC)'

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    That means your project has not been completely changed to MySQL. You can search sqlserver keyword in your solution globally.

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11