繁体   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