Accessing Connection property using DbContext

.net asp.net c# entity-framework

Question

I am upgrading my practice Entity Framework code to v4.1. In old version, I had my context class deriving from ObjectContext but with new release of EF 4.1, they have provided a good DbContext API.

I am basically trying to convert the code so that it works from Database First approach to Code First approach. Playing around with EF 4.1

In old code, I had something like

context.Connection.BeginTransaction(isolationLevel);

where the context Type was deriving from ObjectContext.

In v4.1 I haven't got access to Connection property from context. How can I do that?

1
25
5/10/2011 12:16:54 PM

Accepted Answer

It is in the DbContext and it should be public.

dbContext.Database.Connection.ConnectionString

also:

dbContext.Database.Connection.BeginTransaction(isolationLevel)
53
5/10/2011 12:16:16 PM

Popular Answer

In the brave new .Net Core world, you can use:

context.Database.GetDbConnection()


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow