[英]DbCommand with Linq?
I'm using DbCommand
from : System.ComponentModel.Component
我正在使用DbCommand
: System.ComponentModel.Component
I'm building an object with params : 我正在用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);
And now, I want to iterate it using linq: 现在,我想使用linq迭代它:
IEnumerable<DbParameter> t = from a in command.Parameters select a;
but it's generating following error : 但它产生以下错误:
IEnumerable<DbParameter> t = command.Parameters.Cast<DbParameter>();
You have to use Cast<T>()
because the type of Parameters
is DbParameterCollection
, which implements IEnumerable
(non-generic) but not IEnumerable<T>
. 您必须使用Cast<T>()
因为Parameters
的类型是DbParameterCollection
,它实现IEnumerable
(非泛型)但不是IEnumerable<T>
。 You can write 你可以写
IEnumerable t = command.Parameters;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.