簡體   English   中英

EF 核心 2.2 到 EF 核心 3.1

[英]EF core 2.2 to EF core 3.1

當我以前使用 EF 2.2 時,它可以毫無問題地運行此代碼:

var resource = locResRepo.GetWhere(i => i.ForApplication.ToLower() == applicationName.ToLower())
            .Where(resourcesConditionExpression)
            .Select(item => new ResourceKeyObject
            {
                Id = item.Id,
                ResourceKey = item.ResourceKey,
                ResourceKeyValues = item.ActualLocalizationTranslation
                .Where(translationConditionExpression)
                .Select(v => new ResourceKeyValues
                {
                    Language = v.Language,
                    KeyValue = v.Value

                }).ToList()
            }).ToList();

但現在它拋出錯誤:

System.InvalidOperationException: Processing of the LINQ expression '(MaterializeCollectionNavigation(
    navigation: Navigation: LocalizationResources.ActualLocalizationTranslation,
    subquery: (NavigationExpansionExpression
        Source: DbSet<ActualLocalizationTranslation>
            .Where(a => EF.Property<Nullable<int>>(l, "Id") != null && EF.Property<Nullable<int>>(l, "Id") == EF.Property<Nullable<int>>(a, "ResourceId"))
        PendingSelector: a => (NavigationTreeExpression
            Value: (EntityReference: ActualLocalizationTranslation)
            Expression: a)
    )
        .Where(i => EF.Property<Nullable<int>>((NavigationTreeExpression
            Value: (EntityReference: LocalizationResources)
            Expression: l), "Id") != null && EF.Property<Nullable<int>>((NavigationTreeExpression
            Value: (EntityReference: LocalizationResources)
            Expression: l), "Id") == EF.Property<Nullable<int>>(i, "ResourceId")))
    .Where(t => True)' by 'NavigationExpandingExpressionVisitor' failed. This may indicate either a bug or a limitation in EF Core. See https://go.microsoft.com/fwlink/?linkid=2101433 for more detailed information.
   at Microsoft.EntityFrameworkCore.Query.Internal.NavigationExpandingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor) and so on.....

我真的不明白為什么.. 或者我知道一些東西,但我不知道,如何實現它

從 3.0 開始,不再在客戶端上評估 EF Core LINQ 查詢。 了解更多:MSDN

實際上,我認為您的問題可能出在 i.ForApplication 屬性中,如果它進行了一些計算。

好吧,我找到了解決方案。 由於 EF 3.1 邏輯,select 之前必須是 .ToList()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM