I am trying to migrate a project originally developed using EF4 to EF6 in order to use EF6 transaction management.
The problem I am facing is that the project was created using the Database First approach, so when I use type code context.Database.UseTransaction, I encounter the following error:
The context is being used in Code First mode with code that was generated from an EDMX file for either Database First or Model First development.
This exception is thrown inside the method of OnModelCreatingmy class DbContext.
Any idea?
thank
EDIT:
The fact is that this is legacy code using EDMX with a basic approach to the database. I have to implement EF6 transactions inside this project, so now it will be more like the first code template.
, :
public class MyContext : BaseDbContext
{
public MyContext (DbConnection existingConnection, bool contextOwnsConnection)
: base(existingConnection, contextOwnsConnection)
{
}
}
:
<add name="CS"
connectionString="Data Source=MyServ;Initial Catalog=MyDBName;User Id=MyUser;Password=MyPwd;Pooling=True;Min Pool Size=5;Max Pool Size=20;Persist Security Info=True;MultipleActiveResultSets=True;Application Name=EntityFramework;Enlist=false"
providerName="System.Data.EntityClient" />
providerName System.Data.SqlClient, .
, :
<add name="OrderManagement"
connectionString="metadata=res://*/MyManagementModel.csdl|res://*/MyManagementModel.ssdl|res://*/MyManagementModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=MyServer;Initial Catalog=MyDBName;User Id=MyUser;Password=MyPwd;Pooling=True;Min Pool Size=5;Max Pool Size=20;Persist Security Info=True;MultipleActiveResultSets=True;Application Name=EntityFramework""
providerName="System.Data.EntityClient" />
, , Keyword metadata not supported, , The context is being used in Code First mode with code that was generated from an EDMX file for either Database First or Model First development.