【发布时间】:2017-10-28 21:23:32
【问题描述】:
相同的查询在 .Net 3.5 中有效,但在 .Net 4.5.2 中无效 这里有很多帖子都有同样的错误,几乎都试过了,但没有用。 我已将所有内容提取到一个单独的变量中进行查询。我仍然收到错误 -
LINQ to Entities 无法识别方法“System.String Format(System.String, System.Object)”方法,并且该方法无法转换为存储表达式。
private void LoadAppointmentData()
{
var user = Session["user"].ToString();
var userFirstName = db.Users.SingleOrDefault(u => u.FirstName == user);
var userFN = userFirstName.username;
var chwWorker = from c in db.PatientContacts
where c.UserName == userFN &&
(c.PCP_Status == "Appointment Made" || c.PCP_Status_AWC == "Appointment Made"
|| c.PCP_Status_AWDV == "Appointment Made" ||
(c.PCP_Status == "RX for Mamogram" && c.Status == "Appointment Made"))
orderby c.PCP_Status_Date descending
select new
{
Id = c.MemberID,
Name = c.PatientFirstName + " " + c.PatientLastName,
PCP_Appt = $"{c.PCP_Status_Date:d}",
Mammogram_Appt = $"{c.StatusDate:d}",
Phone = GetPhone(c.MemberID)
};
if (chwWorker.Any())
{
if (grvAppointmentList != null)
{
pnlAppointmentFollowUp.Visible = true;
grvAppointmentList.DataSource = chwWorker;
grvAppointmentList.DataBind();
}
}
}
我不确定要运行此查询还需要进行哪些更改。
【问题讨论】:
-
$"{c.PCP_Status_Date:d}"isString.Format。我假设您知道错误的含义。 -
但在早期版本中也是如此......
-
不,string.Format 从来不是实体框架中支持的方法。我假设您在 .Net 3.5 中使用了 LINQ-to-SQL,它会自动切换到客户端评估 LINQ 查询中无法转换为 SQL 的部分。
-
我尝试转换为 PCP_Appt = string.Format("{0:d}", c.PCP_Status_Date),但仍然收到相同的错误 - “消息”LINQ to Entities 无法识别该方法' System.String Format(System.String, System.Object)' 方法,并且该方法不能翻译成存储表达式。" s
-
@GertArnold,是的,你是对的,我在 .Net 3.5 中使用了 LINQ-to-SQL,
标签: c# asp.net entity-framework linq