O'Reilly logo

Programming Entity Framework, 2nd Edition by Julia Lerman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 21. Manipulating Entities with ObjectStateManager and MetadataWorkspace

It’s time to delve deeper into the Entity Framework and work directly with its core components: the ObjectStateManager and MetadataWorkspace APIs.

These are truly the two workhorses of the Entity Framework. Under the covers, Object Services uses the classes in these two APIs extensively to interact with objects at a granular level. Most of the classes and methods are public, so you can use ObjectStateManager and MetadataWorkspace in your own applications to control and manipulate entity objects.

Separately or together, these two classes not only allow you to manipulate entities, but also enable you to write generic methods that you can use on various Entity Framework object types, as well as dynamically create objects at runtime without depending on the generated entity classes.

Along with learning the concepts of ObjectStateManager and MetadataWorkspace, you will find many code samples in this chapter that you can use in your applications. For example, you will find a set of extension methods to overload the GetObjectStateEntries method and a utility for inspecting in-memory entities at runtime.

You will learn how to interact with entities and entity state through the ObjectStateManager and build the State Entry Visualizer that you saw in Chapter 10. Then you will learn about interacting with the raw metadata using the MetadataWorkspace.

Later in the chapter, you will build more samples that will give you ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required