Creating a Data Service Provider – Part 9 – Un-typed

Background info: This post builds on Parts 1 thru 8 which teach you how to create a typed Data Service Provider. But now the part we’ve all been waiting for- an un-typed DSP – which is what I expect most real world DSP implementations will be based on. What do we mean by Un-typed? An…

10

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 36 – How to Construct by Query

While writing my tips series and writing EF controllers for MVC I found that I regularly wanted to create and attach a stub entity. Unfortunately it isn’t quite that simple, you have to make sure the entity isn’t already attached first, otherwise you’ll see some nasty exceptions. To avoid these exceptions I often found myself…

6

Tip 35 – How to write OfTypeOnly<TEntity>()

If you write a LINQ to Entities query like this: var results = from c in ctx.Vehicles.OfType<Car>()               select c; It will bring back, Cars and any type that derives from Car, like say SportCar or SUV. If you just want Cars and you don’t want derived types like SportCars or SUVs in LINQ to…

4

Maybe there is more

Michel Perfetti, has taken my little Maybe thingie and gone a lot further, by using expression tree re-writting he has made it possible to express this: string code = licensePlate.Maybe(lp => lp.Car)                          .Maybe(c => c.Owner)                          .Maybe(o => o.Address)                          .Maybe(a => a.PostCode); which is NULL safe but very cumbersome like this: string code = licensePlate.Maybe2(lp => lp.Car.Owner.Address.PostCode);…

3