Tip 56 – Writing an OData Service using the Reflection Provider

At TechEd I got a lot of questions about how to expose Data as OData By now you probably know you can use Data Services and the Entity Framework to expose data from a database as an OData Service. You might even know you can use Data Services with a custom Data Service Provider to expose arbitrary data…

2

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

Tip 54 – How to improve performance using Statement Expressions

Background: While writing the update post in my Data Service Provider series I ended up writing this block of reflection code to copy properties values from one object to another: foreach (var prop in resourceType           .Properties           .Where(p => (p.Kind & ResourcePropertyKind.Key)                           != ResourcePropertyKind.Key)) {       var clrProp = clrType            .GetProperties()           …

2

Tip 53 – How to debug EF POCO mapping issues

If you are trying to use POCO classes in EF 4.0, it is relatively easy to run into problems with the mapping from your model to your CLR classes. If you get any nasty problems here, the best way to get to the bottom of things is to try to explicitly load the metadata for…

2

Tip 52 – How to re-use Types with the Data Services client

By default when you add a Data Service Service Reference you get automatic code-generation, which produces a strongly typed DataServiceContext and classes for all your ResourceTypes. You can have a look at this generated code if you ‘show all files’ in your project: And then expand your Data Service Reference, it’s dependant Reference.datasvcmap and open…

2

Tip 50 – How to query a Data Service using JQuery

Recently I’ve been spending some of my time playing with JQuery. And because Data Services can expose data in JSON format, I thought I’d use JQuery to grab some data from a Data Service. Turns out it is pretty simple. This example isn’t going to win any beauty awards, but it will show you the…

6

Tip 49 – How to find your Data Service bug

I’ve been playing around with creating a custom Astoria Data Service Provider, aka DSP, for a while now. So far I’d managed to get my metadata all setup, so browsing to $metadata works great. I’d got a few simple queries work. Basically everything was going fine. At least until I tried this URL: I wasn’t…

4

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