سؤال

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)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top