LINQ到实体无​​法识别方法System.ObjectCompareObjectEqual [英] LINQ to Entities does not recognize the method System.ObjectCompareObjectEqual

查看:168
本文介绍了LINQ到实体无​​法识别方法System.ObjectCompareObjectEqual的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个asp.net页面上的code段在code隐藏文件。我决定把它移动到一个模块(general_functions.vb)在公共子程序。一旦我这样做,但是,code不再适用 - 它抛出一个错误

I had a code segment on an asp.net page in the code-behind file. I decided to move it into a public subroutine in a module (general_functions.vb). Once I did this, however, the code no longer works - it throws an error.

在原来的code-后面我取代了原来的code,象这样的电话:

On the original code-behind I replaced the original code with a call like so:

DeleteResidency(people_id, semester, year)

现在在我的general_functions.vb我创建了一个公用的子程序一样如下:

Now in my general_functions.vb I created a public subroutine like follows:

Public Sub DeleteResidency(delpeople_id, delsemester, delyear)
    Using dbContext as pbu_housingEntities = New pbu_housingEntities
        Dim remove_selection = (From p in dbContext.Residents _
                               Where p.people_code_id = delpeople_id _
                               Where p.year = delyear _
                               Where p.semester = delsemester _
                               Order By p.id Descending _
                               Select p).FirstOrDefault
    End Using
End Sub

有更多code到它比,但高于code是什么引发错误。我得到的错误是:

There is more code to it than that, but the code above is what throws the error. The error I get is:

LINQ到实体无​​法识别方法'System.Object的
  CompareObjectEqual(System.Object的,System.Object的,布尔型)'方法,和
  这种方法不能被翻译成店前pression。

LINQ to Entities does not recognize the method 'System.Object CompareObjectEqual(System.Object, System.Object, Boolean)' method, and this method cannot be translated into a store expression.

谁能帮我明白这是为什么发生?

Can anyone help me understand why this is occurring?

推荐答案

在DeleteResidency子过程的定义中明确键入您的参数。这使得更少的编译器来推断和prevents错误的这些类型。

Explicitly type your parameters in the definition of the DeleteResidency Sub Routine. This leaves less for the compiler to infer and prevents these types of errors.

这篇关于LINQ到实体无​​法识别方法System.ObjectCompareObjectEqual的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆