如何在查询语法中使用实体的方法

问题描述 投票:0回答:1

我需要在查询语法中按dateTime的时间进行排序。我从实体的最后一个“州”获得此字段。

为了获得我的最后状态,我在GetCurrentState()实体中定义了方法VisaRequest;但是当我在let中调用它时,出现错误。

如何解决?

IQueryable<VisaRequest> visaList = (from visa in context.VisaRequest
                                    let createdDate = EntityFunctions.TruncateTime(visa.CreatedDate)
                                    let dateTime = visa.GetCurrentState().CreateDate.Value.Ticks
                                    where visa.Status != Status.Created &&
                                          visa.Status != Status.Pending)
                                   orderby
                                        createdDate descending, visa.Status descending, dateTime descending
                                   select visa).Skip(skip)
                                               .Take(take);
return visaList.ToList();

我收到此错误:

System.NotSupportedException:LINQ to Entities无法识别方法'Visa.Domain.Entity.FlowState GetCurrentState(Visa.Domain.Entity.FlowState)'方法,并且该方法无法转换为商店表达式。

c# linq let
1个回答
0
投票

我想实体框架无法将您的GetCurrentState()方法转换为sql表达式。

请您试试这个

let dateTime = visa.GetCurrentState().AsEnumerable()

AsEnumerable()调用强制在内存中执行以下LINQ方法,而不是尝试将其转换为SQL。

© www.soinside.com 2019 - 2024. All rights reserved.