ObjectContext vs DbContext

6 posts, 1 answers
  1. Doug
    Doug avatar
    18 posts
    Member since:
    Feb 2011

    Posted 02 Dec 2011 Link to this post

    We're really excited about this control as it will really push us forward in a lot of heavy scenarios where "normal" programming falls apart.  I have to echo a previous post that documentation should be a priority.  I think people will simply skip over this if documentation isn't present.

    The thing I'm fighting is this.  We have in our N-Tier architecture a DbContext from a CodeFirst EF model and not a straight ObjectContext.  The fluent api exposed by the DbContext is something we've been using for nearly 6 months now.  I'm getting the underlying ObjectContext from the DbContext using the code below, but I am getting a Query Object Not Found error no matter which table I attempt to tie to.  My guess is that, in reversing a DbContext back to an ObjectContext, I'm losing a lot of my definitions.

    1.  Do you support DbContexts?
    2.  If not (which I suspect is the answer), how could I use this control with a DbContext?

    Thanks!
    Doug

    ((IObjectContextAdapter) GearboxEntities).ObjectContext;
  2. Answer
    Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 05 Dec 2011 Link to this post

    Hello Doug,

    We have decided to build the control to use a plain ObjectContext so that it is compatible with the old .NET 3.5 version of Entity Framework which does not have the DbContext. I am afraid that currently, it will not support a DbContext.

    Maybe in the near? or far? future when we totally dump .NET 3.5 support, we will revamp the control to target solely the DbContext, but I am afraid that I cannot commit to a specific timeframe, since this is a company-wide decision which I cannot make.

    I am really sorry to disappoint you.

    As for the error you are getting, can you please check whether you have a property named the same as the QueryName on your ObjectContex instance? What we do is try to find a public property, i.e. Customers on the ObjectContext by using reflection. If we can't find a public property named 'QueryName' you will see the exception that you are getting.

    Kind regards,
    Ross
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. UI for WPF is Visual Studio 2017 Ready
  4. Doug
    Doug avatar
    18 posts
    Member since:
    Feb 2011

    Posted 13 Dec 2011 Link to this post

    That's a perfectly understandable decision.  We created a separate ORM just for the "power tool grids" we're doing.  You can't seem to get public properties off of a converted IObjectContext now that they've taken the public ObjectContext property off of the DbContext.  Not architecturally "correct", but it gets one heck of a job done.

    Thanks!
    Doug
  5. Mike
    Mike avatar
    26 posts
    Member since:
    Jun 2008

    Posted 14 Dec 2011 Link to this post

    @Doug

    Thanks for your feedback. We have the same problem here and not solved it yet. What I don't understand is this statement of Ross: 

    "As for the error you are getting, can you please check whether you have a property named the same as the QueryName on your ObjectContex instance?"

    What does this means? How did you solve it? Would be great if you could share some more information or code.

    Thanks
    mike
  6. cocowalla
    cocowalla avatar
    15 posts
    Member since:
    Dec 2011

    Posted 31 Jul 2013 Link to this post

    Any updates on this - does the EntityFrameworkDataSource support DbContext now?
  7. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 05 Aug 2013 Link to this post

    Hello,

    Yes, it now has a public DbContext property for .NET 4.5 only.

    In fact, getting the ObjectContext instance from a DbContext instance could easily be done by the developer like this:

    var objectContext =  ((System.Data.Entity.Infrastructure.IObjectContextAdapter)this.DbContext).ObjectContext;


    This is what we do inside the control when you supply a DbContext. But you can use the new property called DbContext -- it will do that for you.

    I hope this helps.

    Regards,
    Rossen Hristov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top
UI for WPF is Visual Studio 2017 Ready