我有以下linq聲明:

( from apiKey in context.Set<ApiKey>()
                    join application in context.Set<Application>() on apiKey.User equals application.User
                    join paymentGateway in context.Set<PaymentGateway>() on apiKey.User equals paymentGateway.User
                    where apiKey.Key == secureRequest.ApiKey
                    where application.Secret == secureRequest.ApplicationSecret
                    where paymentGateway.Id == secureRequest.PaymentGatewayId
                    select apiKey ).AnyAsync();

但據我所知,這是正確的,但當我運行代碼時,我得到以下錯誤。

Expression of type 'System.Collections.Generic.IEnumerable`1[System.Data.Common.DbDataReader]' cannot be used for parameter of type 'System.Collections.Generic.IEnumerable`1[Microsoft.Data.Entity.Query.QuerySourceScope`1[DomainModel.PaymentGateway]]' of method 'System.Collections.Generic.IEnumerable`1[Microsoft.Data.Entity.Query.QuerySourceScope] _Join[QuerySourceScope,QuerySourceScope`1,User,QuerySourceScope](System.Collections.Generic.IEnumerable`1[Microsoft.Data.Entity.Query.QuerySourceScope], System.Collections.Generic.IEnumerable`1[Microsoft.Data.Entity.Query.QuerySourceScope`1[DomainModel.PaymentGateway]], System.Func`2[Microsoft.Data.Entity.Query.QuerySourceScope,PaymentGatewayWrapper.DomainModel.User], System.Func`2[Microsoft.Data.Entity.Query.QuerySourceScope`1[PaymentGatewayWrapper.DomainModel.PaymentGateway],PaymentGatewayWrapper.DomainModel.User], System.Func`3[Microsoft.Data.Entity.Query.QuerySourceScope,Microsoft.Data.Entity.Query.QuerySourceScope`1[DomainModel.PaymentGateway],Microsoft.Data.Entity.Query.QuerySourceScope])'

任何正確方向的指針都會非常感謝。

經過一些調查後,我發現是Any導致了這個錯誤。所以有以下幾點:

( from apiKey in context.Set<ApiKey>()
                        join application in context.Set<Application>() on apiKey.User equals application.User
                        join paymentGateway in context.Set<PaymentGateway>() on apiKey.User equals paymentGateway.User
                        where apiKey.Key == secureRequest.ApiKey
                        where application.Secret == secureRequest.ApplicationSecret
                        where paymentGateway.Id == secureRequest.PaymentGatewayId
                        select apiKey ).ToListAsync();

我收到此錯誤:

The multi-part identifier "application.Secret" could not be bound.
The multi-part identifier "paymentGateway.Id" could not be bound.

如果有人知道這個問題是什麼,但我不認為EF 7支持正常加入

熱門答案

據我所知,Join應該是基本類型。在您的加入中,您似乎加入了對象User但您應該為UserId進行加入。

( from apiKey in context.Set<ApiKey>()
                    join application in context.Set<Application>() on apiKey.UserId equals application.UserId
                    join paymentGateway in context.Set<PaymentGateway>() on apiKey.UserId equals paymentGateway.UserId
                    where apiKey.Key == secureRequest.ApiKey
                    where application.Secret == secureRequest.ApplicationSecret
                    where paymentGateway.Id == secureRequest.PaymentGatewayId
                    select apiKey ).AnyAsync();


Related

許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow