locked
Cannot implicitly convert type 'System.Data.Objects.ObjectContext' to 'System.Data.Entity.Core.Objects.ObjectContext' RRS feed

  • Question

  • Hi There,

    VS 2013.

    I'm a bit of a novice with this stuff and I've been trying to resolve this issue for a couple of days now, and appears to be going round in circles.    It seems that there was a common error with EF 6.0.0, and I have since followed the steps to update the frameworks to what i have now (6.1.0 - beta) .

    I was assuming that https://entityframework.codeplex.com/workitem/1515 was in place to resolve the issue, so I'm either missing something, or going mad. 

    If I refactor the code to replace System.Data.Objects with the new System.Data.Entity.Core.Objects, and remove the reference to System.Data.Entity I'm being told to replace it again.

    When I put it back in, I still get the error above. 

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data.Entity.Core;
    using System.Data.Entity.Core.Objects;
    using System.Data.Entity.Core.Objects.DataClasses;
    using System.Linq;
    using System.Web.DynamicData;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace HH{
        public partial class ManyToMany_EditField : System.Web.DynamicData.FieldTemplateUserControl {
             protected ObjectContext ObjectContext { get; set; }
    
            public void Page_Load(object sender, EventArgs e)
            {
                EntityDataSource ds = (EntityDataSource)this.FindDataSourceControl();
    
                ds.ContextCreated += (_, ctxCreatedEnventArgs) => ObjectContext = ctxCreatedEnventArgs.Context;
    
                ds.Updating += new EventHandler<EntityDataSourceChangingEventArgs>(DataSource_UpdatingOrInserting);
                ds.Inserting += new EventHandler<EntityDataSourceChangingEventArgs>(DataSource_UpdatingOrInserting);
            }

    Error appears here: 

    ds.ContextCreated += (_, ctxCreatedEnventArgs) => ObjectContext = ctxCreatedEnventArgs.Context;

    Half of the solutions suggest removing the reference, half say include it.

    Any thoughts?

    Keith

    Wednesday, March 5, 2014 9:00 AM

Answers

  • Hello KWMFerguson,

    This is because the EntityDataSource does not support EF6 if we do not install an update for the EntityDataSource control which is released recently:

    http://blogs.msdn.com/b/adonet/archive/2014/02/11/preview-of-dynamic-data-provider-and-entitydatasource-control-for-ef6.aspx

    The ctxCreatedEnventArgs.Context comes from System.Data.Objects.ObjectContext while ObjectContext comes from System.Data.Entity.Core.Objects;

    After installing the update, it will change the System.Data.Objects.ObjectContext to System.Data.Entity.Core.Objects.

    And do not forget to replace the tagPrefix “asp” with “ef” in the web form.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Fred Bao Friday, March 14, 2014 7:06 AM
    Thursday, March 6, 2014 3:24 AM

All replies

  • I've just spent several days moving our project from VS2010+MVC2+EF4 all the way to VS2012+MVC5.1+EF6.0.2 so I feel your pain, it's hard to give an advice though.

    Seems something somewhere still creates the System.Data.Objects.ObjectContext while other parts of the solution expect System.Data.Entity.Core.Objects.ObjectContext. Are you sure you've updated all projects in the solution that had a reference to anything EF related? Any third party DLLs related to database? EFExtensions.dll maybe? I ended up having to download the sources and update and recompile that one.

    Any chance you still use the old .tt and EF.Utility.CS.ttinclude? You need to download and use the right one for EF6 - find it in the online gallery.

    Jenda


    http://jendaperl.blogspot.com<br/> A Perl developer in the world of C#

    Wednesday, March 5, 2014 11:55 PM
  • Hello KWMFerguson,

    This is because the EntityDataSource does not support EF6 if we do not install an update for the EntityDataSource control which is released recently:

    http://blogs.msdn.com/b/adonet/archive/2014/02/11/preview-of-dynamic-data-provider-and-entitydatasource-control-for-ef6.aspx

    The ctxCreatedEnventArgs.Context comes from System.Data.Objects.ObjectContext while ObjectContext comes from System.Data.Entity.Core.Objects;

    After installing the update, it will change the System.Data.Objects.ObjectContext to System.Data.Entity.Core.Objects.

    And do not forget to replace the tagPrefix “asp” with “ef” in the web form.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Fred Bao Friday, March 14, 2014 7:06 AM
    Thursday, March 6, 2014 3:24 AM
  • http://blogs.msdn.com/b/adonet/archive/2014/02/11/preview-of-dynamic-data-provider-and-entitydatasource-control-for-ef6.aspx

    That is nearly five years old. I hope I find something that is more current but I seem to be having the same problem. I have been searching for many hours.



    Sam Hobbs
    SimpleSamples.Info

    Thursday, December 6, 2018 2:14 AM
  • http://blogs.msdn.com/b/adonet/archive/2014/02/11/preview-of-dynamic-data-provider-and-entitydatasource-control-for-ef6.aspx

    That is nearly five years old. I hope I find something that is more current but I seem to be having the same problem. I have been searching for many hours.



    Sam Hobbs
    SimpleSamples.Info


    The latest version is EF 6. So how is it that you think the link is not viable? 
    Thursday, December 6, 2018 10:19 AM
  • The latest version is EF 6. So how is it that you think the link is not viable?

    That is the problem. I do not know. I do know that I spent a couple of days searching and trying things that did nothing except introduce possible problems. I did however find something from Microsoft saying they do not want us to use EntityDataSource. The answer is, if you have the correct version applied, use Microsoft.AspNet.EntityDataSource.EntityDataSourceContextCreatingEventArgs instead of System.Web.UI.WebControls.EntityDataSourceContextCreatingEventArgs. Application of the current versions can (and I assume should) be installed by NuGet.



    Sam Hobbs
    SimpleSamples.Info

    Thursday, December 6, 2018 4:07 PM