Microsoft.Data.Sqlite 개요

Microsoft.Data.Sqlite는 SQLite용 경량 ADO.NET 공급자입니다. SQLite용 Entity Framework Core 공급자는 이 라이브러리를 토대로 빌드됩니다. 그러나 독립적으로 또는 다른 데이터 액세스 라이브러리와 함께 사용할 수도 있습니다.

설치

안정적인 최신 버전은 NuGet에서 제공됩니다.

dotnet add package Microsoft.Data.Sqlite

사용법

이 라이브러리는 연결, 명령, 데이터 판독기 등에 공통적으로 적용되는 ADO.NET 추상화를 구현합니다.

using (var connection = new SqliteConnection("Data Source=hello.db"))
{
    connection.Open();

    var command = connection.CreateCommand();
    command.CommandText =
    @"
        SELECT name
        FROM user
        WHERE id = $id
    ";
    command.Parameters.AddWithValue("$id", id);

    using (var reader = command.ExecuteReader())
    {
        while (reader.Read())
        {
            var name = reader.GetString(0);

            Console.WriteLine($"Hello, {name}!");
        }
    }
}

참조