How to Rub DevOps On .NET Core csproj 03 January 2017 Donovan Work (4) In this post I show you how to build the new .NET Core csproj projects with Team Services. [More]
Control the name of your .NET Core output 29 August 2016 Donovan-Brown Work (3) In this post I teach you how to take control of the name of your .NET Core output. [More]
Stop wasting time during .NET Core builds 28 August 2016 Donovan-Brown Work (14) In this post I show you how to disable the populating of the local package cache of .NET Core builds. [More]
Build ASP.NET Core RC2 on Hosted Agents 09 June 2016 Donovan-Brown Work (4) In this post I show you how to use ASP.NET Core on Hosted Agents. [More]
Installing .NET Core RC2 on Ubuntu 16.04 29 May 2016 Donovan-Brown Work (6) In this post I will show you how to install .NET Core RC2 on Ubuntu 16.04. [More]
How to use string.Format with LINQ Select 24 December 2014 Donovan-Brown Work (0) When I project new data types using the Select operator I sometimes want to create new strings from the combination of existing properties. Naturally I turn to string.Format. However, if you attempt a call like the one below: public object Get(int id) { return this.db.People.Where(p => p.Id == id) .OrderBy(p => p.LastName) .Select(p => new { FullName = string.Format(“{0} {1}”, p.FirstName, p.LastName) }) .ToArray(); } I will get the following error: "LINQ to Entities does not recognize the method 'System.String Format(System.String, System.Object, System.Object)' method, and this method cannot be translated into a store expression." The problem is everything that happens before the .ToArray() is parsed and turned into a command that can be sent to the data source. However, LINQ nor would the data source have any idea what to do with System.String.Format. There is a very simply solution. Simply call .ToArray() before you use the Select operator. public object Get(int id) { return this.db.People.Where(p => p.Id == id) .OrderBy(p => p.LastName) .ToArray() .Select(p => new { FullName = string.Format(“{0} {1}”, p.FirstName, p.LastName)}); } That simply change will perform the select after the results have been retrieved from the data source.