2012-01-05 4 views
3

IからDbCommandを使用しています:私はのparamsを持つオブジェクト構築していますSystem.ComponentModel.ComponentDbCommandとLinq?

DbCommand command = _webERPDB.GetStoredProcCommand("mySp"); 
_webERPDB.AddInParameter(command, "@a", DbType.Int32, policyId); 
_webERPDB.AddInParameter(command, "@b", DbType.Int32, appPolicyPrintQaCheckListId); 
_webERPDB.AddInParameter(command, "@c", DbType.Int32, createdBy); 

をそして今、私はLINQを使用して、それを反復処理したい:

IEnumerable<DbParameter> t = from a in command.Parameters select a; 

が、それはです次のエラーが発生しました:

enter image description here

答えて

7
IEnumerable<DbParameter> t = command.Parameters.Cast<DbParameter>(); 

あなたはParametersのタイプはDbParameterCollectionあるのでIEnumerable(非ジェネリック)ではなくIEnumerable<T>を実装する、Cast<T>()を使用する必要があります。あなたは書くことができます

IEnumerable t = command.Parameters; 
+0

私はそれをキャストする必要がありますか?それは既にDbParameterのコレクションです... –

+0

更新された答えを参照してください。 – ken2k