2013-07-13 94 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)與其他方法匹配。爲什麼不在這裏呢? –