2013-07-13 54 views
0

关于新版本微软企业的Libarary 6,他们纷纷打电话的方法ExecuteSprocAccessor应返回Ienumerable<T>当执行SP),这所有的过载是:企业库6 ExecuteSprocAccessor过载?

enter image description here

用法示例:

/*1*/ [Description("Return data as a sequence of objects using a stored procedure")] 
/*2*/   static void ReadDataAsObjects() 
/*3*/   { 
/*4*/    // Create an object array and populate it with the required parameter values 
/*5*/    object[] paramArray = new object[] { "%bike%" }; 
/*6*/    // Create and execute a sproc accessor that uses default parameter and outpu`t mappings 
/*7*/    IEnumerable<Product> productData = defaultDB.ExecuteSprocAccessor<Product>("GetProductList", paramArray); 
/*8*/    //... 
/*9*/    //... 
/*10*/   } 

附加信息:

参数添加机制(此处)非常成问题,因为没有ParameterName to value关联。

他们做的有(第5行)

object[] paramArray = new object[] { "%bike%" };

所以我想如果我有更多然后1个PARAM它看起来像:

object[] paramArray = new object[] { "%bike%",19,"lala"... };

这意味着我必须知道sp的param输入顺序的顺序!

NB

其他方法确实有这种附加价值来命名的:

defaultDB.AddInParameter(sprocCmd, "state", DbType.String, "New York");

问题

是否有使用ExecuteSprocAccessor现在仍然如此ParameterName to value关联的方法吗? (假设我不知道SP输入参数为了

回答

1

内部的IParameterMapper使用这是一个非常简单的接口:

public interface IParameterMapper 
{ 
    /// <summary> 
    /// 
    /// </summary> 
    /// <param name="command"></param> 
    /// <param name="parameterValues"></param> 
    void AssignParameters(DbCommand command, object[] parameterValues); 
} 

这一切都基于位置所以没有太多可以做与开箱代码。

一种选择是写自己的访问者使用该知道如何使用参数名称自定义参数映射器,你可以找到线索Entlib6 DAAB - Using accessors to execute stored procedures with optional parameters?这样的一个例子。

+0

刚奇迹:他们确实做到了'ParameterName to value'(AddInParameter)与其他方法匹配。为什么不在这里呢? –