locked
Why does DbContext accept DbConnection and not IDbConnection? RRS feed

  • Question

  • I am trying to pass in a custom IDbConnection implementation into DbContext.

    I cannot inherit from the abstract class DbConnection, because I need the functionality in the SqlConnection class.

    I cannot inherit from SqlConnection, because the class is sealed.

    I have a class that uses an SqlConnection internally through composition, and implements the IDbConnection interface so it can be used.

    Does anybody know why the DbContext constructor does not accept the interface IDbConnection?

    Isn't it bad practice to accept the concrete class when an interface is available?

    Jamie.

    Wednesday, March 23, 2011 1:53 PM

All replies

  • Hi Jamie,

    This is a limitation of the existing EF components that we are building on top of, they require a DbConnection.

    We may lift this restriction in a future release but it wasn't possible for the current release.

    ~Rowan

    Thursday, March 24, 2011 10:29 PM
    Moderator