none
EF <-> IdbConnection RRS feed

  • Question

  • Hello...

    I'm new to the forums and also new to Entity Framework.

    The firm I'm working for is developing Software which communicates with MS SQL Server 2005-2012
    over idbConnection without EF. Now I'm working on EF to use the known IDBConnection for communicating.
    There is no way to use app.config stored connections. For testing I used Model First + db connection strings but now I've
    to switch to idbconnections and Linq for Entities. (Structure of Database is untouchable)
    I read several pages about EF and IdbConnection and I know the EF doesn't support idbconnections.

    I want to know if there is a way to use a idbconnection with EF. Maybe there is a workaround I haven't found
    or you can give some hints to me.

    Preferred Language VB.net but C# would be ok too..

    Thank you for your time

    Andrew

    • Edited by iTHangover Tuesday, December 4, 2012 12:53 PM
    Tuesday, December 4, 2012 12:50 PM

Answers

  • Then you could create a class that inherits from DbConnection and that wraps the IDbConnection you get from this third party app. Then you'll be able to feed EF with this DbConnection based class (that will use under under the hood the IDbConnection).

    It should bridge the gap (IMHO the 3rd party software should have exposed a DbConnection rather than a IDbConnection interface).


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".

    • Marked as answer by iTHangover Wednesday, December 5, 2012 11:14 AM
    Wednesday, December 5, 2012 9:07 AM

All replies

  • Hi,

    "There is no way to use app.config stored connections." Not sure what you meant ? EF or the other software ? Or is this a company policy ? EF can perfectly use connection strings stored in app.config...

    Else you have a DbContext constructor that accepts a DbConnection (not IDbConnection but IMO the existing software could be based on DbConnection rather than just IDbConnection as providers are based on this abstract class rather on just this interface) : http://msdn.microsoft.com/en-us/library/gg696604(v=vs.103).aspx

    If you can, it seems simpler to just share the same connection string.


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".

    Tuesday, December 4, 2012 1:17 PM
  • Hello...

    I think I've to explain a bit more.

    Based on a 3rd party software (named A) that has some developerinterfaces we have a software (named B) that uses idbcconnection. The interface I'm working on is based on this software B and should handle the datatransfer to database with EF (that's why I test this). As I know, there is no way or no wanted way to use dbconnection string.

    I hope it explains why I'm asking.

    Wednesday, December 5, 2012 8:29 AM
  • Then you could create a class that inherits from DbConnection and that wraps the IDbConnection you get from this third party app. Then you'll be able to feed EF with this DbConnection based class (that will use under under the hood the IDbConnection).

    It should bridge the gap (IMHO the 3rd party software should have exposed a DbConnection rather than a IDbConnection interface).


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".

    • Marked as answer by iTHangover Wednesday, December 5, 2012 11:14 AM
    Wednesday, December 5, 2012 9:07 AM