我开发了一个使用EFCore 2,Xamarin Forms在UWP上完美运行的应用程序但是当我在Android中运行相同时,我的DbContext类的构造函数崩溃了。有时,例外是超时获得一次激活,有时是:
{System.InvalidOperationException: A suitable constructor for type 'Microsoft.EntityFrameworkCore.Internal.DiagnosticsLogger1[Microsoft.EntityFrameworkCore.DbLoggerCategory+Infrastructure]' could not be located. Ensure the type is concrete and services are registered for all parameters of a public constructor.
构造函数是空的,并且没有想到为什么会发生这种情况。我使用的是Xamarin Forms 2.5.0.121934和EnterpriseFrameworkCore SQLite 2.0.1
public class InspectionContext : DbContext
{
//some members here
public static InspectionContext Create(string databasePath)
{
var dbContext = new InspectionContext(databasePath);
dbContext.Database.Migrate();
return dbContext;
}
public InspectionContext(string databasePath)
{
DatabasePath = databasePath;
}
}
我使用以下方法调用上述内容:
var database = InspectionContext.Create(databasePath);
还有另一个查询与我的错误相同,但它在葡萄牙语论坛中。 https://pt.stackoverflow.com/questions/265476/erro-efcore-com-sqlite-no-xamarin-forms-android