Sqlite Generate an C# Model from a Sqlite Database
Generate a C# model from a Sqlite database
Create a new class library project (ensure it has the same .NET major version as the targeted project)
Install nuget package
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
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
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
See the full example on Github