Skip to content

Commit 0056aa1

Browse files
committed
#568 Add support for SQLite
1 parent 494fcd4 commit 0056aa1

File tree

27 files changed

+498
-75
lines changed

27 files changed

+498
-75
lines changed

BuildTT/BuildTT.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ private static void CreateTT(string generatorRoot, string ttRoot)
2727
2828
// For help on the various Types below, please read https://github.com/sjh37/EntityFramework-Reverse-POCO-Code-First-Generator/wiki/Common-Settings.*Types-explained
2929
// The following entries are the only required settings.
30-
Settings.DatabaseType = DatabaseType.SqlServer; // SqlServer, SqlCe, PostgreSQL. Coming next: MySql, Oracle
30+
Settings.DatabaseType = DatabaseType.SqlServer; // SqlServer, SqlCe, SQLite, PostgreSQL. Coming next: MySql, Oracle
3131
Settings.TemplateType = TemplateType.EfCore7; // EfCore7, EfCore6, EfCore5, EfCore3, EfCore2, Ef6, FileBasedCore2-7. FileBased specify folder using Settings.TemplateFolder
3232
Settings.GeneratorType = GeneratorType.EfCore; // EfCore, Ef6, Custom. Custom edit GeneratorCustom class to provide your own implementation
3333

EntityFramework.Reverse.POCO.Generator/Database NorthwindSqlCe40.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// For help on the various Types below, please read https://github.com/sjh37/EntityFramework-Reverse-POCO-Code-First-Generator/wiki/Common-Settings.*Types-explained
1212
// The following entries are the only required settings.
13-
Settings.DatabaseType = DatabaseType.SqlCe; // SqlServer, SqlCe, PostgreSQL. Coming next: MySql, Oracle
13+
Settings.DatabaseType = DatabaseType.SqlCe; // SqlServer, SqlCe, SQLite, PostgreSQL. Coming next: MySql, Oracle
1414
Settings.TemplateType = TemplateType.EfCore7; // EfCore7, EfCore6, EfCore5, EfCore3, EfCore2, Ef6, FileBasedCore2-7. FileBased specify folder using Settings.TemplateFolder
1515
Settings.GeneratorType = GeneratorType.EfCore; // EfCore, Ef6, Custom. Custom edit GeneratorCustom class to provide your own implementation
1616
Settings.UseMappingTables = false; // Must be false for TemplateType.EfCore2 & 3. If true, mapping will be used and no mapping tables will be generated. If false, all tables will be generated.

EntityFramework.Reverse.POCO.Generator/Database.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
// For help on the various Types below, please read https://github.com/sjh37/EntityFramework-Reverse-POCO-Code-First-Generator/wiki/Common-Settings.*Types-explained
1313
// The following entries are the only required settings.
14-
Settings.DatabaseType = DatabaseType.SqlServer; // SqlServer, SqlCe, PostgreSQL. Coming next: MySql, Oracle
14+
Settings.DatabaseType = DatabaseType.SqlServer; // SqlServer, SqlCe, SQLite, PostgreSQL. Coming next: MySql, Oracle
1515
Settings.TemplateType = TemplateType.EfCore7; // EfCore7, EfCore6, EfCore5, EfCore3, EfCore2, Ef6, FileBasedCore2-7. FileBased specify folder using Settings.TemplateFolder
1616
Settings.GeneratorType = GeneratorType.EfCore; // EfCore, Ef6, Custom. Custom edit GeneratorCustom class to provide your own implementation
1717

EntityFramework.Reverse.POCO.Generator/EF.Reverse.POCO.v3.ttinclude

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
{
4141
// Main settings **********************************************************************************************************************
4242
// The following entries are the only required settings.
43-
public static DatabaseType DatabaseType = DatabaseType.SqlServer; // SqlServer, SqlCe, PostgreSQL. Coming next: MySql, Oracle
43+
public static DatabaseType DatabaseType = DatabaseType.SqlServer; // SqlServer, SqlCe, SQLite, PostgreSQL. Coming next: MySql, Oracle
4444
public static TemplateType TemplateType = TemplateType.EfCore7; // EfCore7, EfCore6, EfCore5, EfCore3, EfCore2, Ef6, FileBasedCore2-7. FileBased specify folder using Settings.TemplateFolder
4545
public static GeneratorType GeneratorType = GeneratorType.EfCore; // EfCore, Ef6, Custom. Custom edit GeneratorCustom class to provide your own implementation
4646
public static ForeignKeyNamingStrategy ForeignKeyNamingStrategy = ForeignKeyNamingStrategy.Legacy; // Please use Legacy for now, Latest (not yet ready)
@@ -1532,6 +1532,7 @@
15321532
{
15331533
SqlServer,
15341534
SqlCe,
1535+
SQLite,
15351536
Plugin, // See Settings.DatabaseReaderPlugin
15361537
PostgreSQL,
15371538
MySql, // Not yet implemented
@@ -6948,6 +6949,9 @@
69486949
case DatabaseType.SqlCe:
69496950
return new SqlServerLanguageFactory();
69506951

6952+
case DatabaseType.SQLite:
6953+
return new SQLiteLanguageFactory();
6954+
69516955
case DatabaseType.Plugin:
69526956
return new PluginLanguageFactory();
69536957

@@ -7053,6 +7057,24 @@
70537057
}
70547058
}
70557059

7060+
public class SQLiteLanguageFactory : IDatabaseLanguageFactory
7061+
{
7062+
public IDatabaseToPropertyType Create()
7063+
{
7064+
switch (Settings.GenerationLanguage)
7065+
{
7066+
case GenerationLanguage.CSharp:
7067+
return new SQLiteToCSharp();
7068+
7069+
case GenerationLanguage.Javascript:
7070+
// Not yet supported
7071+
7072+
default:
7073+
throw new ArgumentOutOfRangeException();
7074+
}
7075+
}
7076+
}
7077+
70567078
public class SqlServerLanguageFactory : IDatabaseLanguageFactory
70577079
{
70587080
public IDatabaseToPropertyType Create()
@@ -7305,6 +7327,37 @@
73057327
}
73067328
}
73077329

7330+
public class SQLiteToCSharp : IDatabaseToPropertyType
7331+
{
7332+
// [Database type] = Language type
7333+
public Dictionary<string, string> GetMapping()
7334+
{
7335+
return new Dictionary<string, string>
7336+
{
7337+
{ string.Empty, "string" }, // default
7338+
{ "blob", "byte[]" },
7339+
{ "real", "double" },
7340+
{ "integer", "int" },
7341+
{ "text", "string" }
7342+
};
7343+
}
7344+
7345+
public List<string> SpatialTypes()
7346+
{
7347+
return new List<string>();
7348+
}
7349+
7350+
public List<string> PrecisionTypes()
7351+
{
7352+
return new List<string>();
7353+
}
7354+
7355+
public List<string> PrecisionAndScaleTypes()
7356+
{
7357+
return new List<string>();
7358+
}
7359+
}
7360+
73087361
public class SqlServerToCSharp : IDatabaseToPropertyType
73097362
{
73107363
// [Database type] = Language type
@@ -12317,6 +12370,9 @@ and limitations under the License.
1231712370
case DatabaseType.SqlCe:
1231812371
return "System.Data.SqlServerCe.4.0";
1231912372

12373+
case DatabaseType.SQLite:
12374+
return "System.Data.SQLite";
12375+
1232012376
case DatabaseType.Plugin:
1232112377
return string.Empty; // Not used
1232212378

@@ -13519,6 +13575,7 @@ and limitations under the License.
1351913575
switch (Settings.DatabaseType)
1352013576
{
1352113577
case DatabaseType.SqlServer:
13578+
case DatabaseType.SQLite:
1352213579
return new SqlServerDatabaseReader(factory, databaseToPropertyType);
1352313580

1352413581
case DatabaseType.SqlCe:
@@ -20097,6 +20154,9 @@ using {{this}};{{#newline}}
2009720154
case DatabaseType.Plugin:
2009820155
usings.Add("Microsoft.Data.SqlClient");
2009920156
break;
20157+
case DatabaseType.SQLite:
20158+
usings.Add("Microsoft.Data.Sqlite");
20159+
break;
2010020160
case DatabaseType.PostgreSQL:
2010120161
break;
2010220162
case DatabaseType.MySql:
@@ -21682,6 +21742,9 @@ using {{this}};{{#newline}}
2168221742
case DatabaseType.Plugin:
2168321743
usings.Add("Microsoft.Data.SqlClient");
2168421744
break;
21745+
case DatabaseType.SQLite:
21746+
usings.Add("Microsoft.Data.Sqlite");
21747+
break;
2168521748
case DatabaseType.PostgreSQL:
2168621749
usings.Add("Npgsql");
2168721750
usings.Add("NpgsqlTypes");
@@ -23314,6 +23377,9 @@ using {{this}};{{#newline}}
2331423377
case DatabaseType.Plugin:
2331523378
usings.Add("Microsoft.Data.SqlClient");
2331623379
break;
23380+
case DatabaseType.SQLite:
23381+
usings.Add("Microsoft.Data.Sqlite");
23382+
break;
2331723383
case DatabaseType.PostgreSQL:
2331823384
usings.Add("Npgsql");
2331923385
usings.Add("NpgsqlTypes");
@@ -24948,6 +25014,9 @@ using {{this}};{{#newline}}
2494825014
case DatabaseType.Plugin:
2494925015
usings.Add("Microsoft.Data.SqlClient");
2495025016
break;
25017+
case DatabaseType.SQLite:
25018+
usings.Add("Microsoft.Data.Sqlite");
25019+
break;
2495125020
case DatabaseType.PostgreSQL:
2495225021
usings.Add("Npgsql");
2495325022
usings.Add("NpgsqlTypes");

Generator.Tests.Common/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public static class DbType
1212
public const string SqlServer = nameof(SqlServer);
1313
public const string SqlCe = nameof(SqlCe);
1414
public const string SqlLocalDb = nameof(SqlLocalDb);
15+
public const string SQLite = nameof(SQLite);
1516
}
1617
}
1718
}
Lines changed: 65 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,68 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
3-
<configSections>
4-
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
5-
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
6-
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
7-
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
8-
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
9-
</configSections>
10-
<entityFramework>
11-
<providers>
12-
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
13-
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, EntityFramework6.Npgsql" />
14-
</providers>
15-
<defaultConnectionFactory type="Npgsql.NpgsqlConnectionFactory, EntityFramework6.Npgsql" />
16-
</entityFramework>
17-
<runtime>
18-
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
19-
<dependentAssembly>
20-
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
21-
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
22-
</dependentAssembly>
23-
<dependentAssembly>
24-
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
25-
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
26-
</dependentAssembly>
27-
<dependentAssembly>
28-
<assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
29-
<bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0" />
30-
</dependentAssembly>
31-
<dependentAssembly>
32-
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
33-
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
34-
</dependentAssembly>
35-
<dependentAssembly>
36-
<assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
37-
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
38-
</dependentAssembly>
39-
<dependentAssembly>
40-
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
41-
<bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
42-
</dependentAssembly>
43-
<dependentAssembly>
44-
<assemblyIdentity name="System.Threading.Channels" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
45-
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
46-
</dependentAssembly>
47-
<dependentAssembly>
48-
<assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
49-
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
50-
</dependentAssembly>
51-
<dependentAssembly>
52-
<assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
53-
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
54-
</dependentAssembly>
55-
<dependentAssembly>
56-
<assemblyIdentity name="Microsoft.Extensions.Logging.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
57-
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
58-
</dependentAssembly>
59-
</assemblyBinding>
60-
</runtime>
61-
<system.data>
62-
<DbProviderFactories>
63-
<remove invariant="Npgsql" />
64-
<add name="Npgsql Provider" invariant="Npgsql" description=".NET Framework Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql, Version=4.1.3.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" />
65-
</DbProviderFactories>
66-
</system.data>
3+
<configSections>
4+
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
5+
</configSections>
6+
<entityFramework>
7+
<providers>
8+
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
9+
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, EntityFramework6.Npgsql" />
10+
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
11+
</providers>
12+
<defaultConnectionFactory type="Npgsql.NpgsqlConnectionFactory, EntityFramework6.Npgsql" />
13+
</entityFramework>
14+
<runtime>
15+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
16+
<dependentAssembly>
17+
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
18+
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
19+
</dependentAssembly>
20+
<dependentAssembly>
21+
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
22+
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
23+
</dependentAssembly>
24+
<dependentAssembly>
25+
<assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
26+
<bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0" />
27+
</dependentAssembly>
28+
<dependentAssembly>
29+
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
30+
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
31+
</dependentAssembly>
32+
<dependentAssembly>
33+
<assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
34+
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
35+
</dependentAssembly>
36+
<dependentAssembly>
37+
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
38+
<bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
39+
</dependentAssembly>
40+
<dependentAssembly>
41+
<assemblyIdentity name="System.Threading.Channels" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
42+
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
43+
</dependentAssembly>
44+
<dependentAssembly>
45+
<assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
46+
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
47+
</dependentAssembly>
48+
<dependentAssembly>
49+
<assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
50+
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
51+
</dependentAssembly>
52+
<dependentAssembly>
53+
<assemblyIdentity name="Microsoft.Extensions.Logging.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
54+
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
55+
</dependentAssembly>
56+
</assemblyBinding>
57+
</runtime>
58+
<system.data>
59+
<DbProviderFactories>
60+
<remove invariant="Npgsql" />
61+
<remove invariant="System.Data.SQLite" />
62+
<remove invariant="System.Data.SQLite.EF6" />
63+
<add name="Npgsql Provider" invariant="Npgsql" description=".NET Framework Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql, Version=4.1.3.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" />
64+
<add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
65+
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
66+
</DbProviderFactories>
67+
</system.data>
6768
</configuration>

0 commit comments

Comments
 (0)