Category: Entity Framework

  • Entity Framework’s Code-First with an ObjectContext

    If the following blog interests you, it’s probably because you’re using Entity Framework with a Code-First approach and whatever it is you are trying to do *must* use an ObjectContext instead of the standard DbContext. I’m sure, like me, you thought this shouldn’t be too hard. Then you started hitting roadblocks like, Metadata is required in your connection string. What’s metadata? This is only needed in Database-First so you can tell the framework where your edmx and other definition files are, so why do I need this with Code-First, I don’t have these files?

    This was definitely my first reaction as well. So after much trial-and-error and research, I have the solution!

    (more…)

  • Entity Framework Beginner’s Guide Done Right

    Entity framework is a great ORM provided by Microsoft.  There are a ton of examples of how to get up and running with it really quickly.  The only problem with all of them, is the get you off on the wrong foot.

    In all of the EF example guides, the DbContext class is typically deeply embedded into the core of your code.  This of course is great for Entity framework because the effort to change will be next to impossible – speaking from experience of course here.

    Instead, by making some subtle changes we can integrate Entity framework in a separate layer in case at some later date you wish to replace it.  Of course, you might never need to replace it, but following these simple techniques will allow better segregation of code and even provide simpler unit testing.

    (more…)