Sqlite
Generate an C# Model from a Sqlite Database

Step-By-Step via Fluent API

Generate a C# model from a Sqlite database

To use the full power of Fluent API without any disadvantages, put the code in a own project

Create a new class library project (ensure it has the same .NET major version as the targeted project)

Install nuget package KY.Generator.Fluent in your new generator project

Package Manager .NET CLI
PM> Install-Package KY.Generator.Fluent -Version 8.9.1

Derive a class from GeneratorFluentMain (from KY.Generator namespace)

Override the Execute method

public class GeneratorMain : GeneratorFluentMain
{
    public override void Execute()
    {
    }
}

The read method for Sqlite is contained in the KY.Generator.Sqlite package

Package Manager .NET CLI
PM> Install-Package KY.Generator.Sqlite

Now use this.Read() to prepare read. Use .Sqlite() wiht .UseConnectionString() and .UseTable() to read a model from the database. You can read multiple tables or all all tables at once.

The write method for a C# model is contained in the KY.Generator.Reflection package

Package Manager .NET CLI
PM> Install-Package KY.Generator.Reflection

Use .Write() to prepare generation. Use .Reflection() and .Models() to trigger the model generation.

public class Generator : GeneratorFluentMain
{
    public override void Execute()
    {
        this.Read(read => read
            .Sqlite(sqlite => sqlite.UseConnectionString("Data Source=test.db")
                                    .UseAll()
            ))
        .Write(write => write
            .Reflection(reflection => reflection
                .Models("Output")
                .FieldsToProperties()
            )
        );
    }
}

Rebuild your project

The generator will always run on a build. To force a generation use Rebuild.
See the Visual Studio Output window for trace log

See the full example on Github External Link