Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing Connection property using DbContext

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?

like image 722
DotNetInfo Avatar asked May 10 '11 11:05

DotNetInfo


People also ask

How do I test my EDMX connection string?

Open the edmx (go to properties, the connection string should be blank), close the edmx file again. Open the app. config and uncomment the connection string (save file) Open the edmx, go to properties, you should see the connection string uptated!!

What is DbContext and how is it used?

A DbContext instance represents a combination of the Unit Of Work and Repository patterns such that it can be used to query from a database and group together changes that will then be written back to the store as a unit. DbContext is conceptually similar to ObjectContext.


1 Answers

It is in the DbContext and it should be public.

dbContext.Database.Connection.ConnectionString 

also:

dbContext.Database.Connection.BeginTransaction(isolationLevel) 
like image 67
hazimdikenli Avatar answered Sep 20 '22 06:09

hazimdikenli