簡體   English   中英

與Linq的DbCommand?

[英]DbCommand with Linq?

我正在使用DbCommandSystem.ComponentModel.Component

我正在用params構建一個對象:

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;

但它產生以下錯誤:

在此輸入圖像描述

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

您必須使用Cast<T>()因為Parameters的類型是DbParameterCollection ,它實現IEnumerable (非泛型)但不是IEnumerable<T> 你可以寫

IEnumerable t = command.Parameters;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM