与Linq的DbCommand?

Roy*_*mir 3 c# linq dbcommand

我用的 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);
Run Code Online (Sandbox Code Playgroud)

现在,我想使用linq迭代它:

IEnumerable<DbParameter> t = from a in command.Parameters select a;
Run Code Online (Sandbox Code Playgroud)

但它产生以下错误:

在此输入图像描述

ken*_*n2k 9

IEnumerable<DbParameter> t = command.Parameters.Cast<DbParameter>();
Run Code Online (Sandbox Code Playgroud)

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

IEnumerable t = command.Parameters;
Run Code Online (Sandbox Code Playgroud)