Boris B.
Boris B.

Reputation: 5024

How functional is DbContext as an ObjectContext provider?

We have a large EF 4.0 data framework (based on ObjectContext, EntitySet, EntityObject and ObjectStateManager) which was developed with DB-first in mind. Given that one can obtain an ObjectContext from a DbContext, could we use our existing framework with a code-first DbContext just by using IObjectContextAdapter?

I know that DbContext uses POCOs (and not EntityObject descendants), but those POCOs are internally proxy objects of type Proxy<TPOCO>. Do those proxies inherit or provide access to underlying EntityObject and is there an underlying EntityObject at all?

Upvotes: 1

Views: 277

Answers (1)

cincura.net
cincura.net

Reputation: 4150

Yes, you can use DbContext by casting to IObjectContextAdapter and accessing ObjectContext where needed.

DbContext itself is happy with any class, you can use POCOs without Entity Framework creating proxies. If you use proxy objects, it's just objects derived from your POCO objects. Nothing more, nothing else. Hence there's no EntityObject.

Upvotes: 1

Related Questions