Warning: file_put_contents(/datas/wwwroot/jiajiahui/core/caches/caches_template/2/default/show.php): failed to open stream: Permission denied in /datas/wwwroot/jiajiahui/core/libraries/classes/template_cache.class.php on line 55

Warning: chmod(): Operation not permitted in /datas/wwwroot/jiajiahui/core/libraries/classes/template_cache.class.php on line 56
小巧玲珑调用存储过程和地图结果 - 源码之家

小巧玲珑调用存储过程和地图结果

小巧玲珑调用存储过程和地图结果

问题描述:

我有一个T-SQL存储过程:小巧玲珑调用存储过程和地图结果

CREATE PROCEDURE [dbo].[GetRequestTest] 
     @RequestId UNIQUEIDENTIFIER 
AS 
BEGIN 
    SELECT 
     Request.Amount, 
     Request.Checksum 
    FROM 
     Request 
    WHERE 
     RequestId = @RequestId 
END 

C#映射类:

public class CustomTest : Itest 
{ 
    public decimal Amount {get;set;} 
    public string Checksum { get; set; } 
} 

我打电话试图通过调用存储过程小巧玲珑:

public void Load(CustomTest obj, Guid RequestId) 
{ 
    using (var con = base.GetClosedConnection()) 
    { 
     con.Open(); 

     var p = new DynamicParameters(); 
     p.Add("@RequestId", dbType: DbType.Guid, direction: ParameterDirection.Input);    

     var result = con.ExecuteReader("[dbo].[GetRequestTest]", param: p, commandType: CommandType.StoredProcedure); 

     while (result.Read()) 
      obj.Amount = (decimal)result["Amount"]; 
    }    
} 

但结果是空

我试图调用将存储过程中的SQL语句直接放到C#代码中 - 它工作正常,但它不适用于存储过程。

任何想法 - 如何使它工作?

你叫错了方法:

public void Load(CustomTest obj, Guid RequestId) 
{ 
    using (var con = base.GetClosedConnection()) 
    { 
     con.Open();     

     //result is list of CustomTest 
     var result = db.Query<CustomTest>("GetRequestTest", new {RequestId}, commandType: CommandType.StoredProcedure); 

    }    
} 

如何短小精悍使用:https://github.com/StackExchange/dapper-dot-net

using (var con = base.GetClosedConnection()) 
{ 
    var result = conn.Query<CustomTest>("exec [dbo].[GetRequestTest] @id", new {Id = RequestId}); 
}