Are we forced by CSLA to use DbContext in EF6?

Are we forced by CSLA to use DbContext in EF6?

Old forum URL: forums.lhotka.net/forums/t/12812.aspx


kreid posted on Tuesday, January 13, 2015

I'm hoping someone can correct my ignorance here.

I have upgraded my solution from EF5 to EF6.

I am using ObjectContextManager in my data layer, database-first with an edmx model.

To upgrade to EF6 I followed the guide on MSDN: http://msdn.microsoft.com/en-us/data/upgradeef6.aspx

So now, in my model,

public partial class StoreDataContext : ObjectContext

"ObjectContext" refers to System.Data.Entity.Core.Objects.ObjectContext. Good so far.

However, in my Dal I now have errors everywhere:

using (var ctx = ObjectContextManager<StoreDataContext>.GetManager("StoreDataContext"))

There error is: The type 'Store.DataAccess.Ef.StoreDataContext' must be convertible to type 'System.Data.Objects.ObjectContext' in order to use it as parameter 'C' in the generic class 'Csla.Data.ObjectContextmanager<C>'

Hmm. I tried referencing the Csla.Data.EF6 library, assuming there was something in it that I could use, but it only contains DbContextManager. I need ObjectContextManager - changing to DbContextManager would require massive changes in all my Dal code.

Can someone help?

 

JonnyBee replied on Wednesday, January 14, 2015

Hi,

So EF6 has defined a new base class for ObjectContext that does not inherit from the build-in one in .NET 4/4.5 

In that case - yes there is no builtin support yet.

You should however be able to grab the ObjectContextManager class from CSLA and add to your own assembly and change the generic contraint to be the new ObjectContext for EF6. Then use this class until the support has been added to Csla.EF6.

Issue is created in the backlog. 
https://github.com/MarimerLLC/csla/issues/318  

Copyright (c) Marimer LLC