3

我正在使用 DbCommand来自: System.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;

但它会产生以下错误:

在此处输入图像描述

4

1 回答 1

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

您必须使用Cast<T>(),因为Parametersis的类型DbParameterCollection,它实现IEnumerable(非泛型)但不是IEnumerable<T>. 你可以写

IEnumerable t = command.Parameters;
于 2012-01-05T10:25:05.957 回答