object-context

Entity Framework: Is there a way to check if the context has an object?

Situation: Object in session from a past context can't be set as another object's parent since other object is in a new context. Say I have a User in session that I had retrieved from a context. Now the page reloads, that context has been dismissed, and a new context is made. someUser = context.First(user => user.id == id); Session["...

Need help with ADO.NET Entity Framework UpdateException.

I have in my Database a Contact table and a Phone table, in the phone table there is column "ContactId" with a key that references the phone to the contact. In the key options in the server I set its delete option to 'Cascade'. Now when I attempt to delete a contact using the context: Dim contact As Contact 'The contact I want to dele...

Asynchronous ObjectContext.SaveChanges() ?

Hi all! I want the SaveChanges of the ObjectContext (Win apps) to SaveChanges asynchronously, will show a marquee (or controllable?) progress bar (this I can easily implement) for the user while he is able to continue working. I basically want to override the SaveChanges of the ObjectContext. Has anyone thought about this before? ...

Reuseable ObjectContext or new ObjectContext for each set of operations?

I'm new to the Entities Framework, and am just starting to play around with it in my free time. One of the major questions I have is regarding how to handle ObjectContexts. Which is generally preferred/recommended of these: This public class DataAccess{ MyDbContext m_Context; public DataAccess(){ m_Context = new MyDb...

How can I automatically set a DateUpdated column using the Entity Framework?

I have a bunch of tables that have DateUpdated columns. How can I have those fields automatically set to DateTime.Now when the objects are persisted back to the data store when SaveChanges() is called. I don't need to do it across the board with one piece of code. I would be OK with adding event handlers in all of the partial classes,...

EF: load references after the context was disposed?

Hello everybody. I'm struggling with the ADO.NET Entity Framework. This is my ER-diagram: --------------------- ----------------- --------------- | GrandParentEntity |<-------| ParentEntity |<-------| ChildEntity | +-------------------+ 1 N +---------------+ 1 N +-------------+ | Id | | Id ...

ArgumentException when creating instance of object that inherits from ObjectContext

I'm loosely following an excellent series of blog posts by Kazi Manzur Rashid as a learning exercise for learning how to implement some new (for me at least) design patterns, but I'm getting trouble from the start. I've basically copied his code for the Database, RepositoryBase and RepositoryBaseTests classes, but when I try to run the ...

Best way to keep ObservableCollection and ObjectContext in sync?

Hi, I have window with a listbox bound to an ObservableCollection of People (a set of entity framework objects that I retrieve in response to a users query: a search box), i then have functions such as Edit, Delete and Add New. At the moment i am simply making sure that each time i Add or Remove something from the Database that i also ...

Entity Framework and Object Context lifetime in ASP.NET MVC

Hi there I'm using Entity Framework in my project, and I have the problem that, once I pass my entities to a View (keep in mind that these entities have lazy-initialized objects along the lines of: Products.Owner, where owner is an object that is lazily initialized) I get a run-time exception telling me that the ObjectContext is out of ...

In EntityFramework how do you reload entities in a Many to Many relationship?

Hi First off I'm using .Net 3.5 SP1. I have a few entities related as follows. An Engineer has many Appointments An Appointment has many Engineers A Timeslot has many Appointments I'm providing functionality in my data access layer to undo/discard changes made to entities. I'm doing this by calling... ObjectContext.Refresh(RefreshMod...

How to delete an asociated object in Entity Framework without having access to the object context

Having two models, Site and Link, where a site has many links, how do I delete a link from inside a method of Site, which doesn't have access to the object context? I've tried something like: public void DeleteFirstLink() { var link = LinkSet.First(); LinkSet.Remove(link); } but it seems that is not really deleting the link, ...

Global Javascript Event Handling Object Context

I have the following problem in event handlers in Javascript. I've got an object that has a mousemove event handler like so. function MyObject(){ } functino MyObject.prototype = { currentMousePosition: null, onMouseMove: function(ev){ this.currentMousePosition = this.getCoordinates(ev); }, getCoordinates: functio...

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 Context.SomethingSet.ToList(), our context still contains deleted objects and navigation properties ar...

Entity Framework Object Context in ASP.NET Session object?

Hi there, We have a multi-layered Asp.NET Web Forms application. The data layer has a class called DataAccess which impements IDisposable and has an instance of our Entity Framework Object Context as a private field. The class has a number of public methods returning various collections of Entities and will dispose its Object Context wh...

Why is HttpContext.Current NULL when using an ASP.NET ReportViewer and an ObjectDataSource?

Hi there, I have an ASP.NET Web Forms app using Entity Framework in the data layer. I've recently changed the app over to use one Object Context per request as per this post. It works great for the entire application except for any page which uses a ReportViewer to display something. I've noticed that it fails when trying to get an in...

ADO.net, Check if ObjectContext is writeable

I have an embedded database in an asp.net mvc project. If I try to write to the file, I sometimes get a write failed exception because the SQL Server can't write to the file. How can I check an ObjectContext, if its writeable, without actually writing something to the database? ...

Entity Framework with ASP.NET MVC. Updating entity problem

Hi people. I'm trying to update an entity and its related entities as well. For instance, I have a class Car with a property Category and I want to change its Category. So, I have the following methods in the Controller: public ActionResult Edit(int id) { var categories = context.Categories.ToList(); ViewData["catego...

Refresh ObjectContext or recreate it to reflect changes made to the database?

I have a web service that exposes operations to and from a database. I'm using Entity Framework 4 for the DAL. I'm wondering what would be the best way to handle operations to and from the database. Would it be best not to keep alive an instance of the ObjectContext and instead create one for each operation done to the database? This se...

EF save to Context but not to Datasource

Having a EF Context and a Testenity I want to get the following test to work. TestEntity testEntity = new TestEntity() { Name = "Hello World" }; context.TestEntities.AddObject(testEntity); // missing Code Assert.AreEqual(1, context.TestEntities.Count(), "Entity not in context!"); I know that it works with SaveChanges() but I do not w...