c# - 在 Azure Function 中找不到 EF 的 Getter 方法

标签 c# entity-framework azure exception azure-functions

我正在尝试在 Azure Function 中使用 Entity Framework 。我在本地创建了模型并创建了它的 DLL - 我尝试在控制台项目中使用它,它可以正常工作。

我想在 Azure Function 中执行相同的操作,因此我将 DLL 上传到函数的 bin 文件夹,并在代码中添加了引用:

#r ".\bin\IoTDataModel.dll" 

我还将 EntityFramework 添加到函数本身并引用它:

using System.Data.Entity;
using System.Data.Entity.SqlServer;  
using System.Data.Entity.ModelConfiguration.Conventions;

我编写了一些代码,它使用了我的 DLL 中的模型,并且编译顺利。问题出现在运行时。 示例代码:

using (var context = new IoTDataBaseContext())
{
    var dev = context.Device.FirstOrDefault();
}

抛出此错误:

mscorlib: Exception has been thrown by the target of an invocation. f-EventHubMessageHandler__741454837: Method not found: 'System.Data.Entity.DbSet`1 IoTDataModel.IoTDataBaseContext.get_Device()'

“Device”是我在 EntityFramework 中拥有的模型之一。 通常我无法访问我的任何模型,总是抛出错误。这里可能存在什么问题?

最佳答案

来自related GitHub issue :

if the assembly is properly versioned (i.e. the assembly identity changes as you change the types), this should work as expected and the new version will be resolved. Otherwise; you'll need to restart the function app to resolve the assembly. Deleting the function app is not required.

因此,重新启动您的函数现在应该可以完成工作,但您可能应该考虑对程序集进行版本控制,以防止再次发生这种情况。

关于c# - 在 Azure Function 中找不到 EF 的 Getter 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45279586/

相关文章:

c# - 如何在代码后面调用变量到aspx页面

c# - 无法在下拉列表中选择多个项目

c# - 在查询中使用 lambda 表达式

.net - Linq to Xml:异常-名称中不能包含''字符,十六进制值0x20

c# - 我需要帮助使用 lambda 表达式在 Entity Framework 上下文中查找记录

tcp - 使用端口 1433 的 Azure 输入端点被阻止?

Azure应用服务配置不明确

c# - 从 "1,2,3"解析 int[]

c# - 从两个字典中删除公共(public)键并将剩余部分添加到新的第三个字典中?

entity-framework - 通过在 EF 中指定范围从 ObjectSet 获取对象