Category Archives: Data Access

Recent Interviews & Articles & Videos

Being the lazy gal that I am, I tend to put this info on twitter which is just a passing note, to be forgotten within a day. So I thought I’d collect some of this recent content in one place.

Recent Interviews

Pluralsight does these short interviewes whenever we publish a new course. So this one is for the 3+ hr course I published in September.

This was a fun interview recorded live when I visited the Dot Net Rocks Road Trip in Atlanta on Oct 22.

This is a regular DotNetRocks interview recorded this summer.

Recent Articles

This article provides an overview of what’s new in EF5, from performance improvements to enum support and enhancements to the designer. I think the editors gave the article an unfortunate name.

Upcoming Articles

  • December MSDN Magazine: “Data Points: Pain-Free Data Access in JavaScript—Yes, JavaScript”
  • January 2013 MSDN Magazine: “Data Points: Shrink EF Models with DDD Bounded Contexts”

Recent Videos

Covers implementing Domain Driven Design Bounded Contexts with EF, Repositories & Unit of Work and Automated Testing. The video requires a Pluralsight subscription.

New Entity Framework in the Enterprise Course on Pluralsight

Well..new as in published last month but I never blogged about it.

This is a 3hr16 minute course called “Entity Framework in the Enterprise”.

Learn how Entity Framework fits into your overall software solution when using enterprise level architecture. You’ll see how to implement DDD Bounded Contexts with EF, Repository and Unit of Work patterns and a variety of styles of automated testing. This course is applicable to apps built with V2010, EF4.1+ and .NET 4 as well as with VS2012, EF5 and .NET 4.5.

There are four modules.

1) Architecting the Data Layer (Overview)

2) Bounded DbContext

3) Repositories and Unit of Work

4) Automated Testing

Pluralsight put a 10-minute clip of this on YouTube and the blogged about it. The clip focuses on the Domain Driven Design Bounded Context pattern and how I’ll implement it with Entity Framework. Here is that clip.

The full course (which requires a subscription, but a month for $29 that gives you full access to the entire Pluralsight library is pretty cheap!) . Here’s the link to the course.

I now have 9 Entity Framework courses on Pluralsight which is almost 17 hours worth of content.

Enjoy!

Watch out for VS2012 EDMX Code Generation Special Case

There’s a known problem with EDMX code generation in VS2012. I’ve tested this a number of ways in VS2010 and can’t reproduce the problem there so it seems to be specific to VS2012.

The problem occurs when you have your model inside of a project folder such as in this screen shot:

image

When you make changes to your model, normally, saving the model will trigger the code generator to regenerate the classes.

But when the model is inside a folder, this won’t happen. (It’s not intentional…just a bug.) And you may not realize that this is the problem that’s causing you to have problems during development. Instead you won’t be able to use new (or modified) entities or properties when you are coding against the model because the generated classes weren’t updated.

So, for example, if you change an entity from Contact to Person, (and the EntitySet name will then change from Contacts to People), when you try to write a query against context.People, “People” will not exist as an option. Or if you try to write code related to Person, there will be no such class available.

This is a known issue and has been logged as an item for Entity Framework on the CodePlex site. You can vote for it to raise it’s priority level here: http://entityframework.codeplex.com/workitem/453.

In the meantime, if you want to keep your edmx file inside a project folder, you can still force the code generation to happen by selecting Run Custom Tool from the context menu of the Context.tt file and the model.tt file. Be sure to update BOTH files so that any entity name changes will get picked up by the context as well.

SNAGHTMLf6e3b4b

Thanks to Cori Drew who brought this problem to my attention and to Pawel Kadluczka from the EF team for pointing me to the work item when I had given up on a web search.

You can now start building WinRT apps with OData

Many devs have been waiting for a toolkit so they can consume OData from [Metro] “Windows Store” apps they are building. The Release Candidate of these tools is now on the download center:

WCF Data Services Tools for Windows Store Apps RC:

“The WCF Data Services Tools for Windows Store Apps installer extends the Add Service Reference experience with client-side OData support for Windows Store Apps in Visual Studio 2012.”

 http://www.microsoft.com/en-us/download/details.aspx?id=30714

Mark Stafford from the OData team has written two blog posts that walk you through using the tooling and creating a WinRT (aka Windows Store) app

OData 101: Building our first OData-based Windows Store app (Part 1)

OData 101: Building our first OData-based Windows Store app (Part 2)

Recent Noteworthy Entity Framework Posts You Won’t Want to Miss

I’ve been wanting to do this for a while and I make no promises that I will do this periodically, but here goes.

These are blog posts I’ve linked to twitter, but that’s ancient history after a few hours.


Code First Stored Procedures With Multiple Results
  Posted on August 15, 2012. (Rowan Miller from the EF Team)

 

5 part series on Contributing to newly open-sourced EF by Arthur Vickers (another EF team member)

So you want to contribute to EF? Part 1: Introduction

So you want to contribute to EF? Part 2: The code

So you want to contribute to EF? Part 3: Testing

So you want to contribute to EF? Part 4: Developer experience

So you want to contribute to EF? Part 5: High-level architecture

 

A Troubleshooting Guide for Entity Framework Connections & Migrations

by K.Scott Allen. This one looks like a compilation of emails I have sent to people who ask me questions like this all the time. Kudos to Scott for putting this together.

 

Don’t forget that msdn.com/data/ef is the easy way to get to the Entity Framework Developer Center.

 

I’ve also written some posts on Entity Framework (they all go in my Data Access category). Since you are reading this post, I’ll assume you know how to find those so there’s no point in highlighting them here. Smile

VS2012 EDMX Defaults Now Align with EF Team Guidance re DbContext Usage

Visual Studio 2010 Defaults were defined Prior to DbContext Release

Visual Studio 2010 and .NET 4 were released before Entity Framework’s DbContext existed. DbContext was first released along with Code First in the Entity Framework 4.1 package.

By default, when you create and EDMX (whether Database First or Model First) in VS2010, the code generator will build classes that inherit from EntityObject and  the context created inherits from ObjectContext.

Back then there was also the option of switching to a T4 template that created lighter weight domain classes from your entities while still using ObjectContet as the base class for the generated context.

Please Generate DbContext, not ObjectContext

Along with DbContext, the team released a new T4 template that would generate even *simpler* domain classesa and a context class that inhertied from the newer, smarter and lighter weight DbContext.

The guidance from the team (and I am in full agreement) was to use this DbContext template for any new project, but stick with the older ones if you needed the backward compatibility. This mean downloading EntityFramework from NuGet and doing the special steps to switch to generating with the T4 template.

New Default Behavior for Visual Studio 2012

Now in Visual Studio 2012, the default behavior follows their guidance! Hooray.

When you create an EDMX, Visual Studio 2012 will automatically use the DbContext template to generate the classes and context *and* it will automatically add EntityFramework.dll to your project.

Here you can see the EntityFramework reference, the two new templates and the packages.config (a NuGet asset which tells the project about the downloaded EntityFramework.dll) that were added to the project when I added a new ADO.NET Entity Data Model item to my project.

image

#happiness

A favorite quote about performance optimization

From my book (Programming Entity Framework, 2nd Edition, p.590)

While it’s specific to performance with Entity Framework, I think that it is great advice in general.

From the Horse’s Mouth: Performance Tuning Guidance for Entity Framework

Danny Simmons, who is an architect on the Entity Framework team, gave this great advice on a Channel 9 MSDN podcast he and I participated in together as we were interviewed by Microsoft Sweden’s Dag Konig (http://channel9.msdn.com/posts/buzzfrog/MSDN-Radio-31-Maj–Entity-Framework ):

I give the same recommendation about performance optimization with Entity Framework that I give with any code. Which is: write your code the simplest,
easiest to maintain, most efficient possible way.

And then profile it; find where the problems are and start applying optimizations. And when you do that, you typically will find that there are a set of things you can do to improve performance still using the Entity Framework, and eventually some very small set of cases you may find that the performance is very critical and even after you apply your tricks with entity framework, you need to do something faster than that.

And then you can go to some of the extensibility mechanisms, like writing a stored procedure with hand written sql or those kinds of things to really
optimize those few cases.

And that mix allows you to have very rapid development,  easy to maintain code using the entity framework and then in a very few places have very highly tuned code.