Core class within Entity Framework. Provides the methods to retrieve, query and manipulate entities within the entity model.
Questions tagged [objectcontext]
302 questions
42
votes
6 answers
c# working with Entity Framework in a multi threaded server
What is the best practice for working with entity framework in a multi threaded server?
I'm using entity framework ObjectContext to manage all my database actions, now I know this context isn't thread safe, so for now when I need to use it to…

Eyal
- 10,777
- 18
- 78
- 130
24
votes
2 answers
ExecuteStoreQuery with Dbcontext
I want to use ExecuteStoreQuery function of Entity Framework and I was wondered that my context variable didn't have ExecuteStoreQuery method.
So, I discovered that it's a method of ObjectContext class, but I've already used DbContext for my…

Chuck Norris
- 15,207
- 15
- 92
- 123
22
votes
6 answers
What the heck is a context?
I'm starting to see Contexts everywhere I look. In ASP.NET MVC, there are ControllerContexts, RequestContexts, HttpContexts, FormContexts. In Entity Framework, you have ObjectContexts and DbContexts. Ninject has Ninject.Activation.IContext.
What…

Hobbes
- 370
- 2
- 7
20
votes
2 answers
Provider connection string from Entity Framework
If you are using object contex data model (with EDMX file), during its creation you might want to specify the connection string inside your config file.
The connection string is unfortunately not the common connection string as it contains some…

Mirek
- 4,013
- 2
- 32
- 47
17
votes
3 answers
Entity Framework - Where is my Object Context?
Ok, I'm obviously missing something very basic. I'm very new to Entity Framework.
I want to call stored procedures without importing them, so I was planning on using ExecuteStoreQuery(). According to the documentation, ExecuteStoreQuery is a…

JoeMjr2
- 3,804
- 4
- 34
- 62
16
votes
3 answers
'ObjectContext' vs 'DbContext' in Entity Framework
I'm using the DbContext class within code that I am creating that is based on the Generic Repositories and Unit of Work design patterns. (I am following the guidance here.) While working on this project I have encountered the ObjectContext class.…

afr0
- 848
- 1
- 11
- 29
16
votes
3 answers
How to refresh ObjectContext cache from db?
We are loading data from db:
var somethings = Context.SomethingSet.ToList();
Then someone deletes or adds rows outside of context. Out context still has caches deleted object, because it doesn't know they were deleted. Even if I call…

LukLed
- 31,452
- 17
- 82
- 107
13
votes
4 answers
How to delete a list of object using ObjectContext?
Say you have code like this .
using (CustomerContext db = new CustomerContext())
{
var foundCustList=db.Customers.Where(c=>c.State=='-1').ToList();//Find all the customer which State is -1
foreach(var c in foundCustList)
{
…

Joe.wang
- 11,537
- 25
- 103
- 180
13
votes
4 answers
How do I stop Entity Framework from generating BOTH ObjectContext and dbContext
Background
Visual Studio 2012
NEW Model.EDMX file created in VS2012
Copied some of the EDMX xml from a previously created EDMX into the new one
Problem / Question
Now. The EDMX (TT transform, custom tool, whatever, etc.) is generating BOTH…

Jay Stevens
- 5,863
- 9
- 44
- 67
12
votes
2 answers
Why does Entity Framework automatically use the ObjectContext instead of the DbContext when mapping database tables using ADO.NET Entity datamodel
I am following the database approach first; I have created the tables in my SQL Server 2008 database, then I map those tables to Entity Framework classes using an ADO.NET Entity Data Model. But when I opened the designer.cs file I found the…

John John
- 1
- 72
- 238
- 501
12
votes
1 answer
NullReferenceException when creating ObjectContext in Using statement
Time once again to appeal to greater minds.
I'm experiencing a very strange phenomenon. As the title states, I'm getting a NullReferenceException when trying to create an EF ObjectContext, but I only get the exception if I create the context within…

Troy Frazier
- 391
- 3
- 13
12
votes
5 answers
Self Tracking Entities - AcceptChanges cannot continue because the object's key values conflict with another object in the ObjectStateManager
I've been stuck with this problem for over a week now. Hopefully some one can point me in the right direction.
I start with a brief description of my schema.
Asset 1--->1 Address *-->1 Area *-->1 Region *-->1 Country
Package 1-->* Asset
Using Self…

Tri Q Tran
- 5,500
- 2
- 37
- 58
11
votes
4 answers
ASP.Net Entity Framework, objectcontext error
I'm building a 4 layered ASP.Net web application.
The layers are:
Data Layer
Entity Layer
Business Layer
UI Layer
The entity layer has my data model classes and is built from my entity data model (edmx file) in the datalayer using T4 templates…

Chris Klepeis
- 9,783
- 16
- 83
- 149
11
votes
1 answer
Get DBContext from ObjectContext
I'm using the latest versions of ASP.NET MVC, SQL Server, and Entity Framework. I am not using code first.
I can easily create an object context using the class generated by my EDMX file.
But is there any way to obtain a DBContext object from that…

Jonathan Wood
- 65,341
- 71
- 269
- 466
10
votes
3 answers
Entity Framework - refresh objects from database
I'm having trouble with refreshing objects in my database. I have an two PC's and two applications.
On the first PC, there's an application which communicates with my database and adds some data to Measurements table.
On my other PC, there's an…

Nebojsa Veron
- 1,545
- 3
- 19
- 36