PostgresqlPostgreSQL supports code first to generate tables automatically, although the default schema is dbo instead of public, and auto-increment primary keys can also be generated automatically.
<? xml version = "1.0" encoding = "utf-8"?>
<configuration>
<configSections>
<!-For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468->
<section name = "entityFramework" type = "System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version = 6.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089" requirePermission = "false" />
</ configSections>
<entityFramework>
<defaultConnectionFactory type = "System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value = "v11.0" />
</ parameters>
</ defaultConnectionFactory>
<providers>
<provider invariantName = "System.Data.SqlClient" type = "System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName = "Npgsql" type = "Npgsql.NpgsqlServices, Npgsql.EntityFramework" />
</ providers>
</ entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant = "Npgsql"> </ remove>
<add name = "Npgsql Data Provider"
invariant = "Npgsql"
description = ". Net Framework Data Provider for Postgresql Server"
type = "Npgsql.NpgsqlFactory, Npgsql" />
</ DbProviderFactories>
</system.data>
<connectionStrings>
<add name = "BrKxxContext" connectionString = "server = 127.0.0.1; User Id = postgres; password = energy; database = eftest" providerName = "Npgsql" />
</ connectionStrings>
</ configuration>
SQLite SQLite does not support Code First to automatically generate tables, so it may report an error that the corresponding table cannot be found. There is no way to create the table manually. In addition, although SQLite supports the INTEGER type of increasing primary key, INTEGER is The corresponding type in C # is the type of long or Int64. This is to be noted. When setting the primary key for the Model, you must set the correct type, otherwise there will be problems.
<? xml version = "1.0" encoding = "utf-8"?>
<configuration>
<configSections>
<!-For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468->
<section name = "entityFramework" type = "System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version = 6.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089" requirePermission = "false" />
</ configSections>
<connectionStrings>
<add name = "BrKxxContext" providerName = "System.Data.SQLite.EF6" connectionString = "Data Source = | DataDirectory | BrKxx.db; Pooling = True" />
</ connectionStrings>
<system.data>
<DbProviderFactories>
<remove invariant = "System.Data.SQLite" />
<add name = "SQLite Data Provider" invariant = "System.Data.SQLite" description = ". Net Framework Data Provider for SQLite" type = "System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
<remove invariant = "System.Data.SQLite.EF6" />
<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 "/>
</ DbProviderFactories>
</system.data>
<entityFramework>
<defaultConnectionFactory type = "System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value = "v11.0" />
</ parameters>
</ defaultConnectionFactory>
<providers>
<provider invariantName = "System.Data.SqlClient" type = "System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<!-<provider invariantName = "System.Data.SQLite.EF6" type = "System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />->
<provider invariantName = "System.Data.SQLite" type = "System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
</ providers>
</ entityFramework>
</ configuration>
LocalDB 1. If only LocalDB is installed alone, LocalDB will not automatically start the default process, you need to create or start the corresponding process through the provided SqlLocalDB.exe 2. If only .NET 4.0 is installed on the deployed machine Operating environment, then your application will not be able to access LocalDB, you need to install .NET 4.0.2 or above to access LocalDB normally
<? xml version = "1.0" encoding = "utf-8"?>
<configuration>
<configSections>
<!-For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468->
<section name = "entityFramework" type = "System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version = 6.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089" requirePermission = "false" />
</ configSections>
<entityFramework>
<defaultConnectionFactory type = "System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value = "v11.0" />
</ parameters>
</ defaultConnectionFactory>
<providers>
<provider invariantName = "System.Data.SqlClient" type = "System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</ providers>
</ entityFramework>
<connectionStrings>
<add name = "BrKxxContext" providerName = "System.Data.SqlClient" connectionString = "Data Source = (LocalDb) \ v11.0; Initial Catalog = BrKxx; AttachDbFilename = | DataDirectory | BrKxx.mdf; Integrated Security = True;" />
</ connectionStrings>
</ configuration>
Finally, DataDirectory generally refers to App_Data. If the default value is used, it prompts that the database file cannot be found, or if you want to put the database file in the specified path, you need to manually set the DataDirectory AppDomain.CurrentDomain.SetData ("DataDirectory", Application.StartupPath + "\\ App_Data \\");
Notes and configuration files for connecting Entity Framework 6 to Postgresql, SQLite, and LocalDB