Posted on by & filed under Programming & Development.

As mentioned in a previous blog post, Entity Framework is an object-relational database mapper that enables easy database access (and CRUD) for .NET developers using domain-specific .NET objects that EF can generate for you. You will be thrilled with how easy it can be to do the same type of database tasks using EF that you previously had to write a lot of code to do. And anything that can make my life easier as a developer is okay by me. But sometimes with all that power things may get a little out of sync and you end up scratching your head wanting to know what went wrong.

I had that happen to me, and if I am scratching my head then life definitely isn’t easier. When I was preparing the code for the first blog post I had a problem finding my database. I knew it was created, since my application would run and allow me to add records to the database, but I couldn’t find it anywhere.

Finally, I decided to look in SQLExpress, and I found my database. But why is my database being created using SQLExpress instead of localdb, which is supposed to be the default for EF 5 and Visual Studio 2012? I did some looking around and I noticed this in my app.config:

I did some Bing searches and found references to something called a LocalDbConnectionFactory. Thinking that may be why my database was in the wrong place, I switched my app.config to use the code shown below:

After doing that with a new project and running the application for the first time, my database was created in localdb like it should be. I still haven’t figured out why Entity Framework insists on creating my database in SQLExpress, but I am still looking for the root cause of the problem and if I find it I will blog the solution in my personal blog (see below). In the meantime, I will keep editing my app.config to use the correct connection factory before running my application.

One further tip on Entity Framework that may not be obvious to everyone, deals with using NuGet to install EF. You are not really installing Entity Framework on your computer (or in Visual Studio) as you would other tools. In reality, you are installing it to your project or to your solution. What that means is that EF doesn’t show up somewhere in a Visual Studio menu like the EF Power Tools does. Rather, with EF you will need to install it using NuGet to any project where you want to use Entity Framework for your database access. If you are using the EF Power Tools to reverse engineer an existing database, you won’t need to install EF, since the Power Tools will do that for you as part of the reverse engineering process.

Safari Books Online has the content you need

Check out these .NET Entity Framework books available from Safari Books Online:

Entity Framework 4.0 Recipes: A Problem-Solution Approach provides an exhaustive collection of ready-to-use code solutions for Microsoft’s Entity Framework, Microsoft’s vision for the future of data access. Entity Framework is a model-centric data access platform with an ocean of new concepts and patterns for developers to learn. With this book, you will learn the core concepts of Entity Framework through a broad range of clear and concise solutions to everyday data access tasks. Armed with this experience, you will be ready to dive deep into Entity Framework, experiment with new approaches, and develop ways to solve even the most difficult data access challenges.
Programming Entity Framework: Code First acts as an extension to Programming Entity Framework 2nd Edition. Code First is an additional means of building a model to be used with the Entity Framework and is creating a lot of excitement in the .NET development community. The book begins with an overview of what Code First is, why it was created, how it fits into the Entity Framework and when to use it over the alternatives.
Entity Framework 4.1: Expert’s Cookbook holds many examples to help guide you through tough technical decisions and avoid technical landmines. The book will guide you from just using Entity Framework to enhancing the data access wizard. You will be guided through complex mapping scenarios, query definition, reusability, integration with other technologies, and architectural management. The approach is step-by-step and test driven so that it is focused as much as possible on solving problems and getting the most out of the time spent working through the book.

About the author

Marshall Harrison is the founder of GotSpeech.Net and as well as the owner and CEO of GotSpeech Consulting LLC. He holds a B.S. degree in Computer Science and was a Microsoft MVP from 2006 – 2011. He is currently focusing on Microsoft Lync as well as Windows 8 and Windows Phone 8 devleopment. He can be reached through his blog at

Tags: .NET Entity Framework, CRUD, EF 5, EF Power Tools, NuGet, SQLExpress, Visual Studio 2012,

One Response to “.NET Entity Framework Tip”

  1. ForrestThompson

    When I was preparing the code for the .net programing I had a problem finding my database. Now your entity framework coding are answer key of my problem. thanks again!