ASP. net mvc uses the Petapoco micro ORM framework + NpgSql driver to connect to the PostgreSQL database (problem summary), petapocoorm
The installation process is simple:
1. Before reading the code, we need to load NpgSql and Petapoco into the current project. I will use Nuget to add them to the current project, as shown below:
Install-Package Npgsql
Install-Package PetaPoco
2. Let's take a look at the important code in Web. config.
1> database connection string
<connectionStrings> <add name ="Postgresql" connectionString="Server=127.0.0.1;User id=postgres;password=123;Database=mono_test;" providerName="Npgsql"/> </connectionStrings>
2> NpgSql driver configuration file
<! -- Provider-driven configuration file --> <system. data> <DbProviderFactories> <add name = "Npgsql Data Provider" invariant = "Npgsql" support = "FF" description = ". net Framework Data Provider for Postgresql Server "type =" Npgsql. npgsqlFactory, Npgsql "/> </DbProviderFactories> </system. data>
3. Load Npgsql. dll and Mono. Security. dll to the vs project.
1> put the two dll files in a folder
Open:
Select:
Next step:
Finally:
Reference:
Last:
A demo basic function will be provided later. Background UI reference:
Thanks to the background UI contributed by Elight. MVC.
Sample: