Tip 55 - How to extend an IQueryable by wrapping it.

Over the last couple of years I’ve found myself in lots of situations where I’ve wanted to get ‘under the hood’ and see what is happening inside an IQueryable, but I haven’t had an easy solution, at least until now. Getting down and dirty like this is interesting because it means you can: Log Queries…

5

Creating a Data Service Provider – Part 8 - Relationships

In parts 1 thru 7 we made a Read / Write typed data service provider, although it was a little simplistic because it didn’t have relationships. So lets rectify that right now by adding a relationship to make this more ‘real-world’ Changes to our Classes If you remember from Part 3 we had just a…

2

Custom Data Service Providers

Introduction Data Services sits above a Data Service Provider, which is responsible for interacting with the underlying Data Source on behalf of the Data Service. Data Services ships with some internal providers, and makes it possible for you to create custom providers too. So the obvious question is… Do you need a Custom Data Provider?…

14

Tip 47 – How fix-up can make it hard to change relationships

Problem: Take this code: Category oldCategory = ctx.Categories     .Include(“Products”)     .First(c => c.Name == “Drink”); Category newCategory = new Category {Name = “Beverage”}; foreach(Product product in oldCategory.Products) {     newCategory.Products.Add(product); } Ignore for a second that in this example the solution is probably just to rename the oldCategory “Beverages” – Coming up with real…

2

Tip 46 – How to exclude a property using Code-Only

This time a real simple one prompted by this question on StackOverflow. Problem: If you tell the Entity Framework about this class using Code-Only, by default every property becomes part of Entity, and as a result stored in the database. Usually this is what you want. But not always, imagine this class: public class Person{…

1

Tip 42 – How to create a dynamic model using Code-Only

Background: When we give examples of how to use Code-Only we always start with a strongly typed Context derived from ObjectContext. This class is used to bootstrap the model. For example this (property bodies omitted for simplicity sake): public class MyContext : ObjectContext {     public ObjectSet<Category> Categories { get; }    public ObjectSet<Product> Products…

5

Tip 41 – How to execute T-SQL directly against the database

Sometimes you’ll find you need to issue a query or command that the Entity Framework can’t support. In fact this problem is common to most ORMs, which is why so many of them have a backdoor to the database. The Entity Framework has a backdoor too… .NET 3.5 SP1 In .NET 3.5 SP1 you can…

4

Tip 40 – How to materialize presentation models via L2E

Problem: Imagine that you have these entities public class Product {     public int ID { get; set; }     public string Name { get; set; }     public virtual Category Category { get; set; } } public class Category {     public int ID { get; set; }     public string Name { get;…

5