3

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 :

enter image description here

Pankaj Upadhyay
  • 12,966
  • 24
  • 73
  • 104
Royi Namir
  • 144,742
  • 138
  • 468
  • 792

1 Answers1

10
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;
ken2k
  • 48,145
  • 10
  • 116
  • 176