Postgresql
Postgresql支持Code First的方式自动生成表,不过默认的模式是dbo而不是public,而且还可以自动生成自增主键。
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <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. </configSections>
  7. <entityFramework>
  8. <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
  9. <parameters>
  10. <parameter value="v11.0" />
  11. </parameters>
  12. </defaultConnectionFactory>
  13. <providers>
  14. <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
  15. <provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql.EntityFramework" />
  16. </providers>
  17. </entityFramework>
  18. <system.data>
  19. <DbProviderFactories>
  20. <remove invariant="Npgsql"></remove>
  21. <add name="Npgsql Data Provider"
  22. invariant="Npgsql"
  23. description=".Net Framework Data Provider for Postgresql Server"
  24. type="Npgsql.NpgsqlFactory, Npgsql" />
  25. </DbProviderFactories>
  26. </system.data>
  27. <connectionStrings>
  28. <add name ="BrKxxContext" connectionString ="server=127.0.0.1;User Id=postgres;password=energy;database=eftest" providerName="Npgsql"/>
  29. </connectionStrings>
  30. </configuration>
 
SQLite
SQLite不支持Code First的方式自动生成表,所以可能会报找不到相应的table的错误,没办法只能自己手动建表了,另外,SQLite虽然支持INTEGER类型的自增主键,但是INTEGER在C#中对应的是long或者Int64的类型,这个是要注意的,给Model设置主键时一定要设对类型,不然会出问题。
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <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. </configSections>
  7. <connectionStrings>
  8. <add name="BrKxxContext" providerName="System.Data.SQLite.EF6" connectionString="Data Source=|DataDirectory|BrKxx.db;Pooling=True" />
  9. </connectionStrings>
  10. <system.data>
  11. <DbProviderFactories>
  12. <remove invariant="System.Data.SQLite" />
  13. <add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
  14. <remove invariant="System.Data.SQLite.EF6" />
  15. <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" />
  16. </DbProviderFactories>
  17. </system.data>
  18. <entityFramework>
  19. <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
  20. <parameters>
  21. <parameter value="v11.0" />
  22. </parameters>
  23. </defaultConnectionFactory>
  24. <providers>
  25. <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
  26. <!--<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />-->
  27. <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
  28. </providers>
  29. </entityFramework>
  30. </configuration>
 
LocalDB
1、如果是单独只安装LocalDB的情况下,LocalDB不会自动开启默认的进程,需要通过提供的SqlLocalDB.exe来创建或者开启相应的进程

2、如果部署的机器上只安装了.NET 4.0的运行环境,那么你的应用程序将无法访问LocalDB,你需要安装.NET 4.0.2以上的版本才能正常的访问LocalDB
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <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. </configSections>
  7. <entityFramework>
  8. <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
  9. <parameters>
  10. <parameter value="v11.0"/>
  11. </parameters>
  12. </defaultConnectionFactory>
  13. <providers>
  14. <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
  15. </providers>
  16. </entityFramework>
  17. <connectionStrings>
  18. <add name="BrKxxContext" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=BrKxx;AttachDbFilename=|DataDirectory|BrKxx.mdf;Integrated Security=True;"/>
  19. </connectionStrings>
  20. </configuration>
 
最后
DataDirectory一般是指App_Data,如果使用默认值得情况下,提示找不到数据库文件,或者你想把数据库文件放在指定的路径下,就需要在程序启动的地方人为的设置DataDirectory
AppDomain.CurrentDomain.SetData("DataDirectory", Application.StartupPath + "\\App_Data\\");

Entity Framework 6连接Postgresql、SQLite、LocalDB的注意事项和配置文件的更多相关文章

  1. Entity Freamwork 6连接PostgreSql数据库

    原文 Entity Freamwork 6连接PostgreSql数据库 开发环境 VS 2015  Update 1   Postgre Sql 9.4 使用过程 1.使用Nuget在项目中添加对E ...

  2. 让EF飞一会儿:如何用Entity Framework 6 连接Sqlite数据库

    获取Sqlite 1.可以用NuGet程序包来获取,它也会自动下载EF6 2.在Sqlite官网上下载对应的版本:http://system.data.sqlite.org/index.html/do ...

  3. 如何用Entity Framework 6 连接Sqlite数据库[转]

    获取Sqlite 1.可以用NuGet程序包来获取,它也会自动下载EF6 2.在Sqlite官网上下载对应的版本:http://system.data.sqlite.org/index.html/do ...

  4. Entity Framework入门教程:SQLite数据源访问

    [环境安装] 可以通过NuGet直接搜索安装SQLite需要用到的组件 或者直接使用程序包管理器控制台 > Install-Package System.Data.SQLite 通过ADO.NE ...

  5. [UWP小白日记-11]在UWP中使用Entity Framework Core(Entity Framework 7)操作SQLite数据库(一)

    前言 本文中,您将创建一个通用应用程序(UWP),使用Entity Framework Core(Entity Framework 7)框架在SQLite数据库上执行基本的数据访问. 准备: Enti ...

  6. Entity Framework 6+ 连接Mysql

    好吧.这个博客开不开的 我感觉.. 都一样了. 前言: 公司改造Sqlserver ->Mysql Sql2016老夫对不住你啊.. 好 前沿结束. 需要的家伙: 1.mysql-for-vis ...

  7. Entity Freamwork CodeFirst 连接PostgreSql数据库

    EF的Code First是一个比较强大也比较有用的功能,他可以让你先写代码,最后根据代码去生成数据库,非常符合OO设计的要求,抛开数据库层面不管(当然不是完全的不管),只管对象的设计. 首先,说一下 ...

  8. entity framework core 2.0 & sqlite 配置教程

    我用的是vs2017,需要下载.net core 2.0 sdk. .net core 下载地址:点我下载 1.在Visual Studio之中创建一个.net core的控制台项目 2.修改cspr ...

  9. entity framework core 生成 postgresql 数据库实体

    .net core 2.0 使用db first 方式生成 表 和context PM 控制台运行命令出错 Scaffold-DbContext "Host=localhost;Databa ...

随机推荐

  1. 【C#进阶系列】27 I/O限制的异步操作

    上一章讲到了用线程池,任务,并行类的函数,PLINQ等各种方式进行基于线程池的计算限制异步操作. 而本章讲的是如何异步执行I/O限制操作,允许将任务交给硬件设备来处理,期间完全不占用线程和CPU资源. ...

  2. openresty 前端开发入门二

    这一章主要介绍介绍怎么获取请求参数,并且处理之后返回数据 我们知道http请求通常分为两种,分别是GET,POST,在http协议中,GET参数通常会紧跟在uri后面,而POST请求参数则包含在请求体 ...

  3. java中的switch case

    switch-case语句格式如下 switch(变量){ case 变量值1: //; break; case 变量值2: //...; break; ... case default: //... ...

  4. java 的持久化和序列化的简单理解

    1.对象的持久化(Persistence) 对象持久化就是让对象的生存期超越使用对象的程序的运行期.将对象存储在可持久保存的存储介质上,在实际应用中,运用相应的对象持久化框架,将业务数据以对象的方式保 ...

  5. Apache Spark 1.6 Hadoop 2.6 Mac下单机安装配置

    一. 下载资料 1. JDK 1.6 + 2. Scala 2.10.4 3. Hadoop 2.6.4 4. Spark 1.6 二.预先安装 1. 安装JDK 2. 安装Scala 2.10.4 ...

  6. ipython notebook 浏览器中编写数学公式和现实

    Python Notebook简介1 http://www.cnblogs.com/cbscan/p/3545084.html $ python -m IPython http://pypi.pyth ...

  7. 用drawRect的方式实现一个尺子

    用drawRect的方式实现了一个尺子选择器,demo在这里:https://github.com/Phelthas/LXMRulerView 效果如图:   如果不考虑复用的问题,我感觉最简单的实现 ...

  8. 【代码笔记】iOS-柱状图

    一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...

  9. javascript函数的几种写法集合

    1.常规写法 function fnName(){ console.log("常规写法"); } 2.匿名函数,函数保存到变量里 var myfn = function(){ co ...

  10. 表单中Readonly和Disabled的区别

    1.readonly是要锁定这个控件,通过在界面上无法修改他(但是通过javascript可以修改他). 2.disabled和readonly有相同的地方也是可以锁定这个控件用户不能改变他的值,但是 ...