- 使用 Npgsql
- 使用 EntityFramework6.Npgsql
Install-Package Npgsql
&
Install-Package EntityFramework6.Npgsql
<connectionStrings>
<add name="SampleDbContext" connectionString="Server=localhost;Port=5432;Database=SampleDB;User Id=postgres;Password=123456;" providerName="Npgsql" />
</connectionStrings>
&
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, EntityFramework6.Npgsql" />
</providers>
</entityFramework>
&
<system.data>
<DbProviderFactories>
<remove invariant="Npgsql" />
<add name="Npgsql Data Provider" invariant="Npgsql" support="FF" description=".Net Framework Data Provider for Postgresql" type="Npgsql.NpgsqlFactory, Npgsql" />
</DbProviderFactories>
</system.data>
- BTS001 - 安裝 Npgsql 與 EntityFramework6.Npgsql 組件,版本 3.0.5。
- BTS002 - WebConfig - 1.建立測試用本地DB連線。2.設定DbProviderFactories。
- BTS003 - 1.建立DbContext。2.建立Category Model。3.Enable-Migrations。
- BTS004 - HomeController 建立 GetCategories Action。