Entity Framework使用Sqlite时的一些配置

发表于:2015-7-03 11:04

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:liqipeng    来源:51Testing软件测试网采编

  前段时间试着用Entity Framework for Sqlite环境,发现了一些坑坑洼洼,记录一下。
  同时试了一下配置多种数据库,包括Sqlite、Sql Server、Sql Server LocalDB、Sql Server Compact。
  我建的demo项目结构以及通过NuGet安装的包:
  EFDemo.MultipleDB.UI引用了EFDemo.MutipleDB项目。
  1. 遇到的异常1
  The Entity Framework provider type 'System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SQLite.EF6' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
  我是是引用了Sqlite相关的dll了的(见下图),但是发现生成后再EFDemo.MultipleDB.UI下的生成文件中没有自动将这些dll拷贝过来。

  于是我将这些手动拷贝过来了。
  2. 遇到的异常2
  刚才的异常没了,又出现了一个异常。
  The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
  这次在代码里面加了这么一段,不用调用,只是在代码里让它存在:
  /// <summary>
  /// 解决provider不能自动加载的问题
  /// (不需要调用,放在这里即可)
  /// </summary>
  private static void FixProvidersNotAutoLoadProblem()
  {
  var _ = typeof(System.Data.SQLite.EF6.SQLiteProviderFactory);
  var __ = typeof(System.Data.Entity.SqlServer.SqlProviderServices);
  var ___ = typeof(System.Data.Entity.SqlServerCompact.SqlCeProviderServices);
  }
21/212>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号