dbcontext source for radgrid on EF6

3 posts, 1 answers
  1. Daniel
    Daniel avatar
    16 posts
    Member since:
    Jun 2013

    Posted 20 Feb 2014 Link to this post

    Hello people,

    I have coded my EF5 dbcontext RadGrid datasource as this:

    <telerik:RadGrid ID="RadGrid1"
              runat="server"
              CellSpacing="0" DataSourceID="edsMainGrid"
    ...

    <asp:EntityDataSource ID="edsMainGrid" runat="server" 
                                OnContextCreating="edsMainGrid_ContextCreating"
                                EntitySetName="myCollection">
    </asp:EntityDataSource>

    Protected Sub edsMainGrid_ContextCreating(sender As Object, e As EntityDataSourceContextCreatingEventArgs)
            Dim ctx As myEntities = myEntities()
            e.Context = TryCast(ctx, IObjectContextAdapter).ObjectContext
    End Sub


    and all runs fine in EF5 but ....


    ... I'm migrating to EF6. And, as you know, they are several namespaces ported to EntityFramework.dll.

    My issue is, than, in EF6, an error is raised in this line of code:

    e.Context = TryCast(ctx, IObjectContextAdapter).ObjectContext

    The issue is than e.Context and TryCast(ctx, IObjectContextAdapter).ObjectContext, both are ObjectContext objects, the same type, but declared in separate namespace. The error “Value of type 'System.Data.Objects.ObjectContext' cannot be converted to 'System.Data.Entity.Core.Objects.ObjectContext'“ occurs.

    My question:

    What is the right way to set dbcontext datasource for radgrind in EF6?



    thanks in advance!






  2. Answer
    Radoslav
    Admin
    Radoslav avatar
    1566 posts

    Posted 25 Feb 2014 Link to this post

    Hi Daniel,

    The described error is general and it is not related with our controls. Please check out the following forum threads which elaborate on the same matter.
    http://stackoverflow.com/questions/14106286/ef-6-system-data-objects-objectcontext-error
    http://social.msdn.microsoft.com/Forums/en-US/4ad7ee84-3b73-4cb5-870c-2b5bd7b85ed4/cannot-implicitly-convert-type-systemdataentitycoreobjectsobjectresultstring-to?forum=adodotnetentityframework
    http://www.devexpress.com/Support/Center/Question/Details/Q539957
    https://entityframework.codeplex.com/workitem/806
    http://forums.asp.net/t/1877091.aspx?Tell+me+if+I+am+doing+it+wrong

    I hope this helps.  

    Regards,
    Radoslav
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
  3. Daniel
    Daniel avatar
    16 posts
    Member since:
    Jun 2013

    Posted 23 Apr 2014 in reply to Radoslav Link to this post

    Fixed by MS on Feb'2014

    Install Package Microsoft.AspNet.EntityDataSource:

    PM> Install-Package Microsoft.AspNet.EntityDataSource

    http://www.nuget.org/packages/Microsoft.AspNet.EntityDataSource/

    And change signature handler to:
    Protected Sub edsMainGrid_ContextCreating(sender As Object, e As Microsoft.AspNet.EntityDataSource.EntityDataSourceContextCreatingEventArgs)




Back to Top