2

I am trying to make use of the code in this question to implement a query like this:

    public void LoadLive(DbConnection pConnection)
    {
        using (DbDataReader lReader = pConnection.ExecuteReader("..."))
        {
            mList.AddRange(from t in lReader select new MyObject { Name = t.GetString(0) });
        }
    }

When I attempt to compile this (with the extension method in place), I receive this error:

 error CS1934: Could not find an implementation of the query pattern for source type 'System.Data.Common.DbDataReader'.  'Select' not found.  Consider explicitly specifying the type of the range variable 't'.

Am I missing something about how this is supposed to work?

Community
  • 1
  • 1
Dark Falcon
  • 42,395
  • 5
  • 80
  • 94

3 Answers3

2

You must call the extension method from the answer in the linked question:

 mList.AddRange(from t in lReader.AsEnumerable() 
                select new MyObject { Name = t.GetString(0) });
Ladislav Mrnka
  • 355,666
  • 57
  • 651
  • 662
0

Unless you are going to write your own extension method, Select, Where, etc all return an IEnumerable and the typical method signature will resemble Func<DbDataReader, myT>. What you are looking for is something like Jon Skeet's sample here.

Community
  • 1
  • 1
IAbstract
  • 19,439
  • 15
  • 91
  • 140
0

Compiler error CS1934 is produced when no standard query operators are implemented for a given datasource.

In your case (DbDataReader), you could specify the type of t as IDataRecord:

mList.AddRange(from IDataRecord t in lReader
               select new MyObject { Name = t.GetString(0) });
manji
  • 46,486
  • 4
  • 90
  • 101