• 整理三个PetaPoco连接SQLite数据库的方法


    1. 从https://github.com/qingask/PetaPoco.NetCore下载源文件压缩包
    2. 解压出文件PetaPoco.Multiple.cs、PetaPoco.NetCore.cs
    3. 放置System.Data.SQLite.dll文件到bin文件,这个需要从SQLite官方获取对应框架集级对应位文件,应该可以直接通过NuGet获取。
    4. 方法1:
      1. 增加DbProviderFactories类,向PetaPoco注入SQLite实例
        public static class DbProviderFactories
        {
        
            internal static readonly Dictionary<string, DbProviderFactory> Configs = new Dictionary<string, DbProviderFactory>();
        
            static DbProviderFactories()
            {
                RegisterFactory("Microsoft.Data.Sqlite", SQLiteFactory.Instance);
            }
        
            public static DbProviderFactory GetFactory(string providerInvariantName)
            {
                if (Configs.ContainsKey(providerInvariantName))
                {
                    return Configs[providerInvariantName];
                }
                return null;
            }
        
            public static void RegisterFactory(string providerInvariantName, DbProviderFactory factory)
            {
                if (Configs.ContainsKey(providerInvariantName))
                {
                    Configs[providerInvariantName] = factory;
                }
                else
                {
                    Configs.Add(providerInvariantName, factory);
                }
            }
        
            public static IEnumerable<string> GetFactoryProviderNames()
            {
                return Configs.Keys.ToArray();
            }
        }
      2. 配置web.config
        <add name="PetaPocoConn" connectionString="Data Source=|DataDirectory|Demo.db"/>
      3. 链接语法 
        var db=new Database(new SQLiteConnection(ConfigurationManager.ConnectionStrings["PetaPocoConn"].ConnectionString));
    5.   方法2:
      1.   配置web.config 
        <system.data>
            <DbProviderFactories>
              <remove invariant="System.Data.SQLite"/>         
              <add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" /> 
            </DbProviderFactories>
          </system.data>
      2. 链接字符串:
        <connectionStrings>
            <add name="PetaPocoConn" connectionString="Data Source=|DataDirectory|Demo.db" providerName="System.Data.SQLite" />
          </connectionStrings>
      3. 辅助类:
        public static class DbScoure
            {
                public static Database SqliteDataBase()
                {
                    var conn = ConfigurationManager.ConnectionStrings["PetaPocoConn"];
                    return new Database(conn.ConnectionString, conn.ProviderName);
                }
            }
        调用方式:
        var db=DbScoure.SqliteDataBase();
    6.   方法3 

      1.   
        var db = new Database(conn.ConnectionString, SqlClientFactory.Instance);
  • 相关阅读:
    Django基础篇
    转 枚举设备栈
    转 Windows串口过滤驱动程序的开发
    VS2010 + WinDDK 搭建驱动开发环境(转)
    cef 下载地址
    electron入门教程
    转:PHP 生成复杂JSON格式 简单快速方法
    CEF General Usage(CEF3预览)
    转:关于使用ImageMagick和Tesseract进行简单数字图像识别
    转 Tesseract-OCR 字符识别---样本训练
  • 原文地址:https://www.cnblogs.com/uxinxin/p/8509586.html
Copyright © 2020-2023  润新知