-
Question: One of the questions you often see in the Entity Framework Forums is around sorting related items. For example imagine if you want to query customers, and return only those that have accounts more than 30 days in arrears, and at the same time retrieve their orders. And you need those orders...
-
Question: Where do I find in depth books on the Entity Framework? Answer: One of the benefits of being on a product team a Microsoft is you get authors who want you to review their books. So far to date I've have had 3 different authors send me copies of their Entity Framework books. Here they are...
-
So if you've been reading the Entity Framework Design Blog you will have heard us talk about T4 . It is a technology that ships with Visual Studio 2008 (and 2005 as a separate download). In .NET 4.0 the Entity Framework is leverage T4 to help with Code Generation and Model First scenarios. In fact...
-
The first version of the Entity Framework was released a while back ago now with .NET 3.5 SP1. One of the most glaring holes in the Entity Framework documentation was the lack of a formal document describing the Conceptual Schema Definition Language or CSDL. The CSDL for those who are wondering is the...
-
Imagine you have a model that looks like this: How do you query for just Cars? This is where OfType<SubType>() comes in. You write something like this: var onlyCars = from car in ctx.Vehicles.OfType<Car>() select car; And this works, fine. It restricts the results to just Cars, which incidentally...
-
When should you use eager loading? Usually in your application you know what you are going to "do" with an entity once you have retrieved it. For example if you retrieve an order so you can re-print it for a customer, you know that the re-print would be incomplete without information about...
-
Background If you've been reading the EF Design Blog you will have seen that we recently announced something called " FK Associations " for the EF in .NET 4.0. However in .NET 3.5 SP1, we only support Independent Associations. What that means is that the FK Columns aren't available...
-
Imagine if you have a table of People and you want to retrieve only those whose the Firstname is in a list of interesting firstnames. This is trivial in SQL, you write something like this: SELECT * FROM People WHERE Firstname IN ('Alex', 'Colin', 'Danny', 'Diego') A SQL...
-
Problem The most common way to delete an Entity in the Entity Framework is to pull the Entity you want to delete into the context and then delete it like this: // Find a category by ID by // TRIVIA: in .NET 4.0 you can use .Single() // which will throw if there is more than one match. var category =...
-
The Entity Framework is pretty big, so when the Entity Framework team talks about things internally we tend to use jargon to increase communication 'bandwidth'. Unfortunately sometimes we let this Jargon slip into our APIs and communication. Now jargon is fine if you are in on the secret, but...
-
Background and Motivation: In my last post on EF Jargon I introduced the concept of Relationship Span. If you remember Relationship Span is basically responsible for compensating for the lack of Foreign Key properties* in your Entity. Relationship Span for an Entity, lets say StaffMember, insures that...
-
The Entity Framework supports 3 primary inheritance strategies: Table Per Hierarchy (TPH): In TPH, all data for a type hierarchy is stored in one table, and there is a discriminator column that is used to establish the type of a particular row (i.e. 'C' for Car or 'B' for Boat). Columns...
-
The Problem: In some of earlier tips we talked about using Attach to load things into the ObjectContext in the unchanged state without wearing the cost of doing a query. Attach is the weapon of choice if performance is your goal. Unfortunately our APIs aren't tailored for the 99% case, which is where...
-
Scenario: In order to make applications perform it makes a lot of sense to cache commonly used reference data. Good examples of reference data include things like States, Countries, Departments etc. Generally you want to have this data readily at hand, so you can populate dropdown boxes etc. A good example...
-
Problem: Imagine if you query blog posts: var myPosts = from post in ctx.Posts orderby post.Created descending select post; Just so you can output the post titles etc. foreach(var post in myPosts) { Console.WriteLine("{0} on {1}", post.Title, post.Created); } Well you've just done a lot...