Friday, May 18, 2012

How to write a generic extension for ObjectSet<T> that works with entity types having common property names.

Sometimes you have the same properties in multiple entities.

It is possible to end up duplicating the same logic in the manner of the dreaded copy-modify monster.  I have learned to take it seriously when I find myself doing this because it has never not eventually come back to haunt me .

The key to making this work is to first deploy a couple of simple extension methods to make reflection a bit easier.

Then it is less daunting of a task to write a generic routine that acts on any entity set with common propertie(s).

Sunday, May 6, 2012

Minimal Code to Demonstrate Entity Framework Code First

Before compiling this, to ensure your project has a reference to a version of Entity Framework that supports code first development, execute the following nuget command:

install-package EntityFramework

The following code listing contains:
  • POCO
  • Context
  • Static method to add an item
  • Application configuration (XML)
  • Unit test (not required)