我有以下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();

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

( 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();

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

經過一些調查後,我發現是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 ).AnyAsync();

我收到此錯誤:

( 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();

如果有人知道這個問題是什麼,但我不認為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();



許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
這個KB合法嗎? 是的,了解原因
許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
這個KB合法嗎? 是的,了解原因