1.新建一个MVC框架的ASP.NET Web应用程序项目:


2.打开菜单栏工具下的扩展与更新,找到Npgsql PostgreSQL Interaction插件并安装,这样才能在server explorer中连接到postgresql数据库:




  1. install-package npgsql -version 3.2.7
  2. install-Package EntityFramework6.Npgsql -Version 3.1.1














6.建立好模型后,我们在建立一个模型的控制器,选择Conteoller文件夹右击添加/控制器,选择空的MVC 5控制器:



7.在Web config 里添加如下代码:

  1. <data>
  2. <DbProviderFactories>
  3. <remove invariant="Npgsql" />
  4. <add name="Npgsql Data Provider" invariant="Npgsql" description=".Net Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql" support="FF" />
  5. </DbProviderFactories>
  6. </data>




  1. usingModels;
  2. using System;
  3. usingCollections.Generic;
  4. usingLinq;
  5. usingWeb;
  6. usingWeb.Mvc;
  7. namespace Controllers
  8. {
  9. public class TestController : Controller
  10. {
  11. // GET: Test
  12. public ActionResult Index()
  13. {
  14. Database myDatabase = new Database();
  15. //查询
  16. var list = from s instudent
  17. select s;
  18. return View(list);
  19. }
  20. }
  21. }






  1. @model IQueryable<Models.student>
  2. @using Test.Models
  3. @{
  4. Layout = null;
  5. }
  6. <!DOCTYPE html>
  7. <html>
  8. <head>
  9. <meta name="viewport" content="width=device-width" />
  10. <title>Index</title>
  11. </head>
  12. <body>
  13. <div>
  14. <table border="1">
  15. <tr>
  16. <th>学号</th>
  17. <th>姓名</th>
  18. </tr>
  19. @foreach (student s in Model)
  20. {
  21. <tr>
  22. <td>@s.sno</td>
  23. <td>@s.sname</td>
  24. </tr>
  25. }
  26. </table>
  27. </div>
  28. </body>
  29. </html>



  1. MapRoute(
  2. name: "Default",
  3. url: "{controller}/{action}/{id}",
  4. defaults: new { controller = "Test", action = "Index", id = UrlParameter.Optional }
  5. );







  • Merziuz

    JMX9RF http://pills2sale.com/ viagra online

  • Guillermo

    Wonderfull great site <a href="https://www.dans-hobbies.com/crestor-et-augmentation-des-gamma-gt-jbqq">crestor off patent</a> At Sharp, the situation is more dire. "Sharp has no core products other than LCD," according to Morikawa. LCD accounted for 18.5 percent of company sales in 2011. The figure had risen to 26.2 percent by 2012, with sales rising by 276.32 billion yen ($2.84 billion).

  • Mackenzie

    I'm interested in this position <a href="http://jajharkhand.in/wp/obat-hajar-jahanam-mesir-jakarta-1rp4">testimoni hajar jahanam asli</a> Other new or surging consumer issues included fake fronts called skimmers on gas pumps and automated teller machines. The skimmers collect users' financial information, which can later be used to gain access to the victim's credit or bank accounts.

  • Mya

    How would you like the money? <a href="https://museuvictormeirelles.museus.gov.br/cheapest-clomid-no-prescription-qop3">ovulation after taking clomid</a> If lip balm doesn't do the trick you should consult a doctor. "Cracks at the corners of your mouth may be a sign of a vitamin deficiency," Dr. Raj says. "Have a doctor check your levels—and consider taking a multivitamin."

  • Harley

    Which university are you at? <a href="http://magnocentrojoyero.com/blog/centre-spcialis-pour-sclrose-en-plaque-vmy1">cialis online bestellen per nachnahme</a> It&#39;s not much, but it&#39;s a start &mdash; and a darned sight better than the 18 months beforehand, which the euro zone spent languishing in the longest recession it&#39;s ever seen. Not everyone contributed equally to this little victory, however: Germany and France are doing most of the heavy lifting, while Spain, Italy, the Netherlands and others continue to struggle.

  • Jacques

    What do you do for a living? <a href="http://www.wepsolutions.co.in/avanafil-farmaco-generico-qrnf">havana club 7 anos anejo </a> A newly married man, in some difficulty with his wife, asked an astroleger when his troubles would be over. The astroleger told him to wait for seven and a half years. Anxiously the guy asked again: &#8220;Will everything be all right then?&#8221; &#8220;No, you will get used to them!&#8221; replied the astroleger. Nothing will come out of the discussion. We will be back in square one.




博文总数:750 评论总数:320333

原创126 翻译20 转载604