The normalized data model of the database is often not suitable for reading and displaying data. A separate read model used to represent all the data needed to display a page improves performance. Defining the read model is only half the work though, to make it really usable the read model should accept queries in… Continue reading IQueryable Read Model Extension Methods
Tag: Extension Methods
Emulating Multiple Inheritance with Extension Methods
Last week I showed some ways to utilize extension methods. In this post I’ll go on with a more advanced example and also discuss some of the limitations. Method-Only Multiple Inheritance A combination of interfaces and extension methods can be used to partly work around the single inheritance limitation of C#. Assume that I have… Continue reading Emulating Multiple Inheritance with Extension Methods
Simplify Syntax with Extension Methods
Extension methods were first introduced with LINQ in C#3.0. They are just a syntactic construct, but as we’ll see in this post they can make a huge difference. What’s easier to read of these two? string[] wishList1 = Enumerable.ToArray( Enumerable.Select(Enumerable.Where(Animals, a => a.StartsWith("A")), a => string.Format("I want a {0}.", a))); string[] wishList2 = Animals.Where(a… Continue reading Simplify Syntax with Extension Methods
Indexed SelectList Factory
In the Type Safe SelectList Factory post I showed one way to improve the SelectList constructor. Recently I wrote another one, when I needed a SelectList that has the selected item’s index as the value. I used this together with jQuery to get details about the selected item from a separately supplied json array.
Null Handling with Extension Methods
Often we cannot be sure if a parameter passed in to a function has a value. To write error safe code all those parameters have to be checked for null and handled. We have the ?? coalesce operator to help, but still it can be quite a lot of code. Through the use of extension… Continue reading Null Handling with Extension Methods