. NET of ef+postgresql matters.

Source: Internet
Author: User
Tags connectionstrings

Entity Framework 6 Connection PostgreSQL, SQLite, localdb Considerations and configuration Files-Xuantime 2014-09-03 01:05:00 Blog Park essence Area Original http://www.cnblogs.com/znlgis/p/3952673.html

Postgresql

PostgreSQL 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--<SectionName="EntityFramework"Type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, version=6.0.0.0, culture=neutral , publickeytoken=b77a5c561934e089 "requirepermission="False"/></Configsections><Entityframework><DefaultconnectionfactoryType="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework" ><Parameters><ParameterValue="V11.0"/></Parameters></Defaultconnectionfactory><Providers><ProviderInvariantname="System.Data.SqlClient"Type="System.Data.Entity.SqlServer.SqlProviderServices, Entityframework.sqlserver"/><ProviderInvariantname="Npgsql"Type="Npgsql.npgsqlservices, Npgsql.entityframework"/></Providers></Entityframework><System.data><Dbproviderfactories><RemoveInvariant="Npgsql" ></Remove><AddName="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 the table, so you may not find the corresponding table error, there is no way to manually build the table, in addition, SQLite supports the integer type of the self-key, but the integer in C # The corresponding is a long or Int64 type, this is to note that the model to set the primary key must be set to the type, otherwise it will be problematic.

<?XML version= "1.0" encoding= "Utf-8"?><Configuration><Configsections><!--For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468--<SectionName="EntityFramework"Type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, version=6.0.0.0, culture=neutral , publickeytoken=b77a5c561934e089 "requirepermission="False"/></Configsections><Connectionstrings><AddName="Brkxxcontext"Providername="System.Data.SQLite.EF6"connectionstring=The Data source=| datadirectory| brkxx.db; Pooling=true "/></Connectionstrings><System.data><Dbproviderfactories><RemoveInvariant="System.Data.SQLite"/><AddName="SQLite Data Provider"Invariant="System.Data.SQLite"description=". Net Framework Data Provider for SQLite"Type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite"/><RemoveInvariant="System.Data.SQLite.EF6"/><AddName="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><DefaultconnectionfactoryType="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework" ><Parameters><ParameterValue="V11.0"/></Parameters></Defaultconnectionfactory><Providers><ProviderInvariantname="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 "/>-->" span class= "tag" ><provider invariantname= "System.Data.SQLite" type= " System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6 "/> </ providers> </ entityframework> </ Configuration>              

LocalDB

1, if it is only installed LocalDB, LOCALDB will not automatically open the default process, you need to provide the SqlLocalDB.exe to create or open the corresponding process

2. If you deploy a machine with only. NET 4.0 running environment installed, then your application will not be able to access localdb, you need to install. NET 4.0.2 or more versions to access the LOCALDB

<?XML version= "1.0" encoding= "Utf-8"?><Configuration><Configsections><!--For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468--<SectionName="EntityFramework"Type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, version=6.0.0.0, culture=neutral , publickeytoken=b77a5c561934e089 "requirepermission="False"/></Configsections><Entityframework><DefaultconnectionfactoryType="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework" ><Parameters><ParameterValue="V11.0"/></Parameters></Defaultconnectionfactory><Providers><ProviderInvariantname="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>          

At last

DataDirectory generally refers to App_Data, if the use of the default is worth the case, the hint can not find the database file, or you want to put the database file under the specified path, you need to start the program in the place of artificial settings datadirectory

AppDomain.CurrentDomain.SetData ("DataDirectory", Application.startuppath + "\\App_Data\\");

. NET of ef+postgresql matters.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.