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
  • 43,592
  • 5
  • 83
  • 98

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
  • 360,892
  • 59
  • 660
  • 670
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,551
  • 15
  • 98
  • 146
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
  • 47,442
  • 5
  • 96
  • 103