C# – Search XML for elements, values, and attributes

The simplest way to search XML is to use the Linq-to-XML API in .NET (in System.Xml.Linq). This parses XML and allows you to perform Linq queries on it. Here’s an example: This outputs: XElement is the main class. You use it in combination with Linq methods to perform searches. In this article, I’ll how to … Read more

CA1806: When a method returns a new instance and the instance is ignored

The official title of the CA1806 analyzer warning is “Do not ignore method results,” but this doesn’t really show up in the list of warnings. Instead of showing this generic message, when CA1806 is triggered, it shows very specific text about what triggered the warning. In this article, I’ll show a few examples of code … Read more

EF Core – Aggregate SELECT queries

In this article, I’ll show how to use EF Core to aggregate data for the whole table, per group, and how to only include groups that meet a condition. I’ll show three different aggregates – count, sum, and average. In each scenario, I’ll show the LINQ query, the SQL query it generated, and the results … Read more