简体   繁体   中英

DbCommand with Linq?

I'm using DbCommand from : System.ComponentModel.Component

I'm building an object with 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:

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> . You can write

IEnumerable t = command.Parameters;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM