访问使用的DbContext连接属性属性、DbContext

2023-09-04 23:45:55 作者:◇、pAsT_亚熙

我升级我的做法实体框架code至V4.1。在旧版本中,我有我的上下文类从ObjectContext中,但与EF 4.1的新版本中派生,他们已经提供了很好的DbContext API。

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.

我基本上想转换的code,使得它的工作原理,从数据库First方法code第一种方法。玩弄EF 4.1

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

在旧的code,我有这样的事情

In old code, I had something like

context.Connection.BeginTransaction(isolationLevel);

在上下文类型从ObjectContext的推导。

where the context Type was deriving from ObjectContext.

在V4.1我没有从上下文中获得连接属性。我该怎么办呢?

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

推荐答案

这是在的DbContext,它应该是公开的。

It is in the DbContext and it should be public.

dbContext.Database.Connection.ConnectionString

也:

dbContext.Database.Connection.BeginTransaction(isolationLevel)