简体   繁体   中英

C# Entity Framework 6 Context Object Database First with existing DbConnection

I am new to Entity Framework and i don't know how to solve this problem.

I got an existing System.Data.Common.DbConnection with which i have to initialize the Context-Object in a Database First Scenario. I have tried this constructor

public DbContext(DbConnection existingConnection, DbCompiledModel model, bool contextOwnsConnection), 

but it looks like its only for Code First. Is it possible to use an existing DbConnection with Database First?

The problem was that the DbConnection was not an Entity Connection and this means the Connection works as Code First.

It works if i create a EntityConnection with the DbConnection and create the right Workspace and then use the Entity Connection with this contructor:

public DbContext(DbConnection connection, bool contextOwnsAndDisposesTheConnection)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM