2016-08-04 67 views
0

给定的PostgreSQL(9.5)存储过程(与Npgsql的驱动程序)为:如何从PetaPoco(使用Npgsql)执行PostgreSQL存储过程?

CREATE OR REPLACE FUNCTION “GetAllDx”( patient_recid整数,不受时间区 tencounter时间戳)RETURNS SETOF view_dx

这是如何从PetaPoco执行的?可以做到吗? (我一直在使用Dapper)。

任何帮助,非常感谢。

回答

0

很简单,

[TestMethod] 
     public void GetAllPatientsWithServices() 
     { 
      // Create a PetaPoco database object 
      var db = new chaosDB("localconnection"); 

      // Calling stored procedure getallpatientswithservices() 
      var a = db.Fetch<view_patient>("Select * from getallpatientswithservices()"); 

      foreach(var b in a) 
      { 
       Console.WriteLine("{0} - {1}", b.cpatient, b.chart_number); 
      } 
     } 

或者,用大小写混合的过程名:

[TestMethod] 
     public void GetDxLibrary() 
     { 
      // Create a PetaPoco database object 
      var db = new chaosDB("localconnection"); 

      // Calling stored procedure with mixed case name 
      var a = db.Fetch<icd9>("Select * from \"GetDxLibrary\"()"); 

      foreach (var b in a) 
      { 
       Console.WriteLine("{0} - {1}", b.code,b.cdesc); 
      } 
     }