1

I am trying to find an interface which is implemented by SqlDataReader and which exposes HasRows, Read() and NextResult(). I need these property and methods because I need to read multiple resultSets returned by stored procedures (as mentioned here). Currently I am using System.Data.IDataReader which exposes Read() and NextResult() but not HasRows property.

I need an interface so that the coupling will be lose and for the sake of code testability.

Any help on such an interface? Or I'll need to write an abstraction layer of interface from scratch?

3
  • 2
    There is no such interface. You should write it yourself. Commented Oct 29, 2016 at 8:50
  • Why dont you implement IDataReader for Read() and NextResult() in your own Interface and then implement your own custom interface for hasRows this will reduce your scratchwork Commented Oct 29, 2016 at 9:32
  • IDataReader itself is fine because IDataReader.NextResult() returns a bool so you can do do { ... } while (reader.NextResult()); See for instance this answer. Commented Oct 31, 2016 at 6:54

1 Answer 1

3

HasRows is not needed for anything (usually it's being used redundantly because people don't know any better). The standard pattern is:

while (reader.Read()) ...

So this obviates the need for the interface you are looking for.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.