Tip of the day: Going quickly to an item in the Entity Model Diagram

After a conversation recently about how difficult it was to find stuff in the EDMX diagram because it can often be a right pigs breakfast, I stumbled across this today. In Visual Studio there is a Model Browser that is available when viewing the diagram. It appears in the same space as the solution explorer. […]

Getting Entity Framework to Pick up on the Auto-generated Part of the Composite Primary Key

In my previous post, I wrote about how to get SQL Server to automatically generate a composite primary key for a table when part of that key is also a foreign key to a parent table. That all works nicely in SQL Server and using regular ADO.NET commands from a .NET application. However, as the […]

Checking for NULL using Entity Framework

Here is a curious gotcha using the Entity Framework: If you are filtering on a value that may be null then you may not be getting back the results you expect. For example, if you do something like this: var result = context.GarmentsTryOns .Where(gto => gto.WeddingId == weddingId && gto.PersonId == personId); And personId is […]

Getting just the columns you want from Entity Framework

I’ve been looking at trying to optimise the data access in the project I’m working on, and the major stuff (like getting a piece of code that generated 6000 queries down to just 7) is now done. The next step is to look at smaller things that can still make savings. At the moment, the […]

Entity Framework query that never brings back data

I was recently optimising some data access code using the Entity Framework (EF) and I saw in the SQL Server Profiler this following emanating from the application: SELECT CAST(NULL AS varchar(1)) AS [C1], CAST(NULL AS varchar(1)) AS [C2], CAST(NULL AS varchar(1)) AS [C3], CAST(NULL AS bit) AS [C4], CAST(NULL AS varchar(1)) AS [C5], CAST(NULL AS […]

Entity Framework: Unable to load the specified metadata resource.

Recently, I was refactoring some code and I moved the location of the .edmx file into a different folder (and new namespace). I updated the code to use the new namespace but when I ran the application a MetadataException was thrown with the message “Unable to load the specified metadata resource.” When the location of […]