我正在尝试在 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 中拥有的模型之一。 通常我无法访问我的任何模型,总是抛出错误。这里可能存在什么问题?
最佳答案
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/