I’m in an environment where placing the raw connection string anywhere in my application is not possible. I can only obtain a DB2Connection via an in-house tool. Is it possible to use Entity Framework by giving it an existing connection instance instead of specifying a connection string?
I’m in an environment where placing the raw connection string anywhere in my application
Share
Yes. You can create
EntityConnectionwhich acceptsDbConnectionand pass it toObjectContext. The problem is that passedDbConnectionmust be closed. But still you need a connection string to connect EDMX designer to your database (if you want to use model or database first approach with EDMX).In case of DbContext API (EFv4.1 and fluent mapping) you can pass
DbConnectiondirectly but again it must be closed.