Browse by Tags

Tagged Content List
  • Blog Post: 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...
  • Blog Post: 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...
  • Blog Post: 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...
  • Blog Post: Another C# trick: Fluents, Inheritance and Extension Methods

    Here’s a scenario which Damien and I encountered recently. We needed a way of specifying Facets for properties on Entities, i.e. things like Nullable , MaxLength , Precision etc. And we needed a class hierarchy because different types of properties have different sets of available facets. The...
  • Blog Post: A silly C# trick from the trenches

    UPDATE: as Joe rightly points out in the comments (thanks Joe) when you try to pass a Func<T,V> to a method expecting Action<T> using lambda syntax it doesn't fail. Somehow the compiler must realize there is no match for Func<T,V> and look for a match for with Action<T> as a parameter...
  • Blog Post: I never knew: C# method overloads can return different types

    I came to C# from Java, which I’m pretty sure doesn’t (or maybe didn't) allow this, so I was super surprised today when I learnt that C# method overloads can have different return types. So this class is completely valid: public class Foo { public Foo Bar(); public string Bar(Foo foo); } For...
  • Blog Post: An enumeration of one?

    Having something enumerable is the gateway to all LINQ’s loveliness. But sometimes you have just one object. So how do you make that enumerable? var people = new Person[] {person}; Not exactly hard huh? In fact you can simplify this even more, you can replace new T[] with just new [] like this: var people...
  • Blog Post: LINQ to Objects and Buffer<T>

    I was debugging a problem a couple of days ago, when I learned something interesting. I had some code that looked like this: foreach(Employee e in manager.Manages) { … } The manager.Manages property returned a custom implementation of ICollection<Employee> that lazy-loads it’s data from somewhere...
  • Blog Post: Sample Oracle Provider for EF

    Jarek has released his sample provider for Oracle here . In his post he talks about a few of the more notable challenges he had and how he got around them. If you are writing an EF provider this is gold!
  • Blog Post: Fantasy Soccer - part 3 - Unit of Measure

    Today I spent a bit of time working on the data model for my fantasy soccer application. I don't want to talk about the actual model today though, because I'm not really ready. What I want to do is talk about a problem that occurred to me, namely Unit Of Measure. Any real sport fan knows you...
  • Blog Post: Intellisense : What properties are required?

    Yesterday I was talking to a Simon, another super smart dev on the EF team, and he raised a big concern, one that I am sure you can all relate too: We've all seen something like this: And thought: "What is the bare minimum I can do here to save a Whatever ?" This "What properties are required...
  • Blog Post: 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...
  • Blog Post: Maybe I'm just a little slow...

    But I only just realized that extension methods are cool for avoiding NullReferenceExceptions . We all know that if you have something like this: LicensePlate licensePlate = null ; Car car = licensePlate.Car; It will throw a NullReferenceException . However if you have an extension...
  • Blog Post: Rolling your own SQL Update on top of the Entity Framework - Part 4

    Okay so we've got to the interesting bit at last. We've hooked up our extension method, we've got a query for filtering the records we are updating, we've got a map from object Properties to database Columns. So now comes the interesting bit... We now have to build the UPDATE [Table] SET Column...
  • Blog Post: Rolling your own SQL Update on-top of the Entity Framework - Part 3

    Okay, okay, okay... yes I know this is the slowest moving series in the history of blogging (sorry Roger J). Now, when a blog post starts like that, you would probably expect the next sentence to begin with "But" or "However", not this time though, I have no excuse, I will simply make an appeal to...
  • Blog Post: LINQ to non-enumerable?

    So I was reading Wes' latest post about Monad's a while back (which incidentally is well worth a read, it is the first good explanation of Monad 's I've seen that uses a language I am comfortable with in it's examples, namely C#). Well one thing Wes kind of brushes over is the fact that he ends up...
  • Blog Post: Rolling your own SQL Update on top of the Entity Framework - Part 2

    Okay so it has taken me a while to get to the second part of this post... but as they say better late than never. As I've said before when designing this sort of API, I always like to start with the end in mind... this is what I want the Update() method to look like: public static int Update<T>...
  • Blog Post: Rolling your own SQL Update on-top of the Entity Framework - Part 1

    One of the current limitations of the Entity Framework, is that in order to modify an entity you have to first bring it into memory. Now in most scenarios this is just fine. There are however some bulk update cases where performance suffers somewhat. For example imagine if you need to move all unshipped...
  • Blog Post: ObjectQuery<T>.ToTraceString() and possibilities...

    So in Beta3 of the EntityFramework (due out very soon) the team added a new function to ObjectQuery <T> that allows you to get the native Query that would be evaluated if you enumerated. I.e. if you are using the System.Data.SqlClient that would be the TSQL. This is very handy because it means...
  • Blog Post: Hydrating a DataTable from an EntityDataReader - Part 2

    See yesterday's post for some context... So we can't rely on EntityDataReader . GetSchemaTable() and a DataAdapter to do the filling of our DataTable for us. We have to do it ourselves. As with any problem the first step is to define the steps: Get a DataTable with a shape that matches the...
  • Blog Post: T CastByExample<T>(object o, T example)

    So earlier today I was lamenting that an anonymous type can't be shared between functions with Wes Dyer , when he said "Well actually they can..." Cue me learning something cool. The first step is to create a seemingly innocent method: public static T CastByExample<T>( this object o, T...
Page 1 of 1 (21 items)