【问题标题】:linQ to entities does not recognize the method Models.Repository.Student get_Item(Int32)' methodlinQ to entity 无法识别方法 Models.Repository.Student get_Item(Int32)' 方法
【发布时间】:2017-12-20 06:14:12
【问题描述】:

在 where 子句中出现此错误。 尝试在实体框架中使用 linQ 查询从 sql server 获取记录。

 var Stud = contextSchool.Student.Where(x => x.STDNT_ID == lstStudent[i].StudentID).FirstOrDefault();

如果我将列表的值存储在变量中,然后在 where 子句中使用,它可以工作,但不适用于列表。

完全错误: linQ to entity 无法识别 Models.Repository.Student get_Item(Int32)' 方法,并且该方法无法翻译成存储表达式。

【问题讨论】:

标签: entity-framework linq-to-sql


【解决方案1】:

我在其他一些项目上也遇到了这个错误,问题是你不能使用像 get_Item 或 f.e. 这样的方法。 AddDays() 在你的 linq 命令中。

所以你不得不玩弄它

你必须在你的 linq 命令之前创建一个对象(列表或其他),并用你需要的数据(每个方法)填充它,并在你的 linq 命令中使用变量。

【讨论】:

    猜你喜欢
    • 2011-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-02
    相关资源
    最近更新 更多