Recent articles About

Compiling enterprise

Ivan Koshelev blog on software development

Technical interviewer guide [2017 July 09] Technical interviewing

This article sums up my experience conducting 100+ technical interviews for a big software development outsourcer\outstuffer. It is aimed at interviewers with the goal of helping them prepare for the process and handle typical issues that come up as well as responsibility to both their company and the person being interviewed.

continue reading
Expression trees and advanced queries in C# 03 Expression Tree modification [2017 May 28] .NET, C#, IQueryable, Expression Tree, Expression Visitor

In part 1 we learned that you can swap parts of an Expression Tree to another compatible (i.e. with a matching return type) expression. Swapping is, in fact, the easiest thing to do - with a bit more work we can construct a serializable representation of almost any bit of C# code. This opens great avenues for Domain Driven Development and introducing hot-swappable, dynamic, yet safe parts of logic to your application.

One of the best examples of the power we get is shown by introducing a reusable expression function with LINQKit.

internal static class AddressSubqueries
internal static Expression<Func<string, string, string>> FormatCityAndProvince =
    (city, province) => "The glorious city of " + city 
                            + " of the wonderful province of " + province;
//used like this:
public IQueryable<string> GetStandardAddressDescription(int addressId)
    return DataContext
                .Addresses.AsExpandable() // this hooks in LINQKit 
                .Where(x => x.AddressId == addressId)
                    adr => adr.StateProvinceId,
                    prov => prov.StateProvinceId,
                    (adr, prov) => AddressSubqueries.
                                        FormatCityAndProvince // <==
                                            .Invoke(adr.City, prov.Name))
continue reading
Expression trees and advanced queries in C# 02 IQueryable composition [2017 May 14] .NET, C#, SQL, IQueryable, Composition

In the previous part we have determined that:

  1. IQueryably consists of a Provider and an Expression Tree
  2. Expression Trees can be combined almost as easily as pieces of C# code
And as a result, IQueryables are easily composable.

In this article, we will look at treating our queries are reusable chunks of logic and combining them into more complex yet still readable queries like this:

public IQueryable<ProductModelOrderStatisticsDto> GetProductModelOrderStats()
    // a bigger, more detailed query
    IQueryable<WorkOrderSummaryDto> allDurationsAndRoutings = 

    // is wrapped by an aggregation to retrieve statistics
    var averagePerModel = allDurationsAndRoutings
                .GroupBy(x => new { x.ProductModelId, x.ModelName })
                .Select(x => new ProductModelOrderStatisticsDto
                    ModelId = x.Key.ProductModelId,
                    ModelName = x.Key.ModelName,
                    AverageDuration = x.Where(y => y.DurationDays.HasValue)
                                        .Average(y => y.DurationDays.Value),
                    AverageRoutings = x.Average(y => y.RoutingsCount)

    return averagePerModel;
continue reading
Expression trees and advanced queries in C# 01 IQueryable and Expression Tree basics [2017 May 07] .NET, C#, IQueryable, Expression Trees

Many .NET developers don’t realize or don’t pay attention to the differences between IEnumerable and IQueryable. Most tutorials on the topic don’t go beyond trivial examples, thus missing the huge potential hidden inside.

IQueryable is IEnumerable and much more.

continue reading
newer >
Ivan Koshelev photo

I'm passionate for anything that can be programed and automated to make life better for all of us.


  1. January 2022 (2)
  2. November 2021 (1)
  3. May 2021 (1)
  4. March 2020 (1)
  5. August 2019 (1)
  6. July 2019 (1)
  7. May 2019 (1)
  8. February 2019 (1)
  9. October 2017 (1)
  10. August 2017 (3)
  11. July 2017 (3)
  12. May 2017 (3)


  1. GitHub@IKoshelev
  2. NuGet@IKoshelev
  3. LinkedIn