Second Stanza

August 23, 2008

ADO.NET Entity Framework ObjectContext Issues

Filed under: .NET Development, ADO.NET Entity Framework — Tags: — dfbaskin @ 8:04 am

Some questions come to mind when using the ObjectContext containing your entities.

First, what should the lifetime of an ObjectContext be? Is it like a connection object that should be opened and then closed quickly? When working with your entities, would it be more common for your entities to be attached or detached from an ObjectContext? For example, on your ASP.NET page or Windows Form, would you have an ObjectContext object and your business entities? Or are these objects manipulated in a lower business layer (as Danny Simmons suggests here)?

This thread discusses these issues.

Related to this (and mentioned in the above links) is the idea of abandoning the changes to a set of entities. At this point, there is no RejectChanges method on the ObjectContext. So how do you reset your entites back to a known state? This thread discusses options for accomplishing this.

Rick Strahl has some good related thoughts.

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: