How can i use dapper to connect to a sqlite database?

后端 未结 2 975
Happy的楠姐
Happy的楠姐 2021-02-12 17:40

How can I use dapper to connect and get data from a sqlite database?

2条回答
  •  梦毁少年i
    2021-02-12 18:07

    Here is a complete working example with an in-memory database. Requires C# 8.0.

    using System;
    using System.Data.SQLite;
    using Dapper;
    
    namespace First
    {
        // dotnet add package System.Data.SQLite.Core
        // dotnet add package Dapper
        class Program
        {
            static void Main(string[] args)
            {
                string cs = "Data Source=:memory:";
    
                using var con = new SQLiteConnection(cs);
                con.Open();
    
                var res = con.QueryFirst("select SQLITE_VERSION() AS Version");
    
                Console.WriteLine(res.Version);
            }
        }
    }
    

    Running the example:

    $ dotnet run
    3.30.1
    

提交回复
热议问题