This is a migrated thread and some comments may be shown as answers.

ObjectContext vs DbContext

5 Answers 257 Views
EntityFrameworkDataSource
This is a migrated thread and some comments may be shown as answers.
Doug
Top achievements
Rank 1
Doug asked on 02 Dec 2011, 11:11 PM
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;

5 Answers, 1 is accepted

Sort by
0
Accepted
Rossen Hristov
Telerik team
answered on 05 Dec 2011, 09:28 AM
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 >>

0
Doug
Top achievements
Rank 1
answered on 13 Dec 2011, 03:29 PM
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
0
Mike
Top achievements
Rank 1
answered on 14 Dec 2011, 07:13 PM
@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
0
cocowalla
Top achievements
Rank 1
answered on 31 Jul 2013, 12:07 PM
Any updates on this - does the EntityFrameworkDataSource support DbContext now?
0
Rossen Hristov
Telerik team
answered on 05 Aug 2013, 06:23 AM
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 >>
Tags
EntityFrameworkDataSource
Asked by
Doug
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Doug
Top achievements
Rank 1
Mike
Top achievements
Rank 1
cocowalla
Top achievements
Rank 1
Share this question
or