Skip to main content

Posts tagged with 'csharp advent'

It's the second annual C# Advent 2022 awards! Every year, you all put out such great stuff. Every post is the best!

But, I wanted to do something to recognize the best of the best: the standouts from the latest Advent that have performed above and beyond, and give everyone a chance to revist them and give the Advent one last "hurrah".

Some of these rewards are based on stats like Google Analytics and Reddit upvotes. Some of them are completely arbitrary. I hope you enjoy!

☝ Most Reddit Upvotes

I make sure all of the articles are submitted to /r/csharp and /r/dotnet (with permission of the respective admins). Here are the posts that got the most (combined) upvotes (as of January 5th, 2022):

1. How To Structure Your .NET Solutions by James Hickey - pulled in over 160 upvotes

2. Building Windows Services in .NET 7 by Kevin Griffin - with over 90 upvotes, I'd say there's life left in Windows development

3. Validating .NET Configuration by Chris Ayers - a cool, unique topic gets over 50 upvotes

🖱 Most Clicks from the C# Advent Site

I use Google Analytics on the site. This award pretty much went to the first three participants this time around. Here are the posts that have been most clicked on from the site.

1. Hello from the GitHub Actions: Core .NET SDK by David Pine

2. Web Scraping and Generating PDFs Using C# and .NET by Christopher C. Johnson

3. Validating .NET Configuration by Chris Ayers

🤓 Matt's Favorite

Every post is great and appreciated, but these in particular stuck out to me as especially interesting, fun, and/or useful. Got favorites of your own? Leave a comment below, tweet #csadvent, and write your own C# Advent Awards blog post (and tell me about it, so I can tweet it and link to it)!

1. Generating C# bindings for native libraries by using ChatGPT - ChatGPT is all the rage, but I think this post shows that ChatGPT can be a very efficient and incredibly useful code generation tool.

2. Colorful ASCII Christmas Tree in C# by ChatGPT - This is a much sillier use of ChatGPT, but I love it because of its silliness AND because of how well it ties into Advent in general. AND it is (partially) a blog post written by ChatGPT too. Extraordinarily creative!

3. Advent of Code 2022 via C# - One of a handful of crossovers between the C# Advent and other advents. This post highlights another great advent and shows off C#.

🐣 Best Newcomer

The best content from someone who has never been on the C# Advent before. The criteria is a combination of all the above.

1. Jonathan "J." Tower - J is a long time C# developer community stalwart, and I'm happy to have him on board the C# Advent for the first time with Top-Level Statements in C#

2. Matthias Jost - Filled in for a dropped day with a great post that everyone can enjoy: How Do I Follow My Favourite .NET Blogs?

3. Brendan Enrick - Another long-time community contributor joins with 11 Ways of Making Your C# Harder to Use

👴 Best Veteran

Same as above, except for those who have posted to the C# Advent before.

1. Matt Eland - Thank you for your TWO contributions this year (one to fill in for a dropped day) - Text Classification in C# with ML.NET 2.0 and Interactive C# with Polyglot Notebooks

2. Jonathan Danylko - Has been a part of C# Advent since the beginning, thank you for Creating Multi-Tier Subscriptions using C#

3. Barret Blake - Another long time Advent contributor brings us Turning Any JSON API Into An App

Honorable Mention to Baskar Rao for being a veteran of every year AND having the most total contributions (seven - he contributed twice in 2017)

Thank you to everyone who participated! I've already started planning enhancements for next year. Be sure to watch mgroves on Twitter, the C# Advent site, and this very blog for announcements when the calendar gets toward the last third.

Thank you Smashing Magazine for featuring the Advent Calendars For Web Designers And Developers (2022 Edition) round-up.

Thank you Sergey Tihon for the inspiration.

A special extra thanks to Calvin Allen, who does a lot of behind-the-scenes work on C# Advent (including the domain name, LinkedIn, the CsAdvent twitter account, testing, and much more) even while juggling the arrival of a new family member. Congratulations and thank you!

It's the first ever C# Advent 2021 awards! Every year, you all put out such great stuff. Every post is the best!

But, I wanted to do something to recognize the best of the best: the standouts from the latest Advent that have performed above and beyond, and give everyone a chance to revist them and give the Advent one last "hurrah".

Some of these rewards are based on stats like Google Analytics and Reddit upvotes. Some of them are completely arbitrary. I hope you enjoy!

☝ Most Reddit Upvotes

I make sure all of the articles are submitted to /r/csharp and /r/dotnet (with permission of the respective admins). Here are the posts that got the most (combined) upvotes (as of January 5th, 2022):

1. Don't Do That, Do This: The .NET 6 Edition - Dave Brock killed it with over 300 upvotes

2. String Interpolation Trickery and Magic with C# 10 and .NET 6 - Brant Burnett bringing in around 150 votes

3. Using DateOnly and TimeOnly in .NET 6 to Simplify Your Code - from Christopher C. Johnson, grabbing around 100 votes

🖱 Most Clicks from the C# Advent Site

I put Google Analytics on the C# Advent site for the first time this year. This award will favor the earlier participants, of course. Here are the posts that have been most clicked on from the site.

1. Fastest way to enumerate a List<T> from Gérald Barré got 292 clicks from 272 users

2. The shortest quine in C# 9 and 10 from Martin Zikmund got 276 clicks from 259 users

3. Using C# and Auto ML in ML .NET to Predict Video Game Ratings got 242 clicks from 225 users

🤓 Matt's Favorite

Every post is great and appreciated, but these in particular stuck out to me as especially interesting, fun, and/or useful. Got favorites of your own? Leave a comment below, tweet #csadvent, or write your own C# Advent Awards blog post!

1. Can You Teach C# as a First Language for Kids? - Excellent points made about the strengths and challenges, some great examples and ideas.

2. Fastest way to enumerate a List<T> - Straightforward topic, easy to understand, and introduced me to BenchmarkDotnet!

3. Parallel.ForEachAsync Deep Dive - Again, I was introduced to a tool that I wasn't aware of, and I can potentially make use of.

🐣 Best Newcomer

The best content from someone who has never been on the C# Advent before. The criteria is a combination of all the above.

1. Sarah Dutkiewicz - I can't believe it's Sarah's first time, but she killed it. She claimed day 1, which may be the most challenging day. AND she filled in for someone who dropped out, just two days later. Well done!

2. Matthew MacDonald - My favorite entry this year is from a first-timer.

3. Alvin Ashcraft - Another author who I can't believe is a first-timer! Check out Calling the Microsoft Graph API from WinUI

👴 Best Veteran

Same as above, except for those who have posted to the C# Advent before.

1. Brant Burnett - One of the first to sign up back in 2017, and he has delivered every year since. This year his post was especially popular: String Interpolation Trickery and Magic with C# 10 and .NET 6

2. Ed Charbeneau - Another great post this year. Ed is one of the most enthusiatic participants, and he always creates a great entry: Accessibility Test–Driven Blazor Components

3. Baskar Rao - He is a workhorse when it comes to the C# Advent. A unique topic this year: A Quick Peek of Accessibility Insights and Automating Desktop Applications

Honorable Mention to Roman Stoffel, just because I love the illustrations in Automated Tests Advice, C# Edition

Thank you to everyone who participated! I've already started planning enhancements for next year. Be sure to watch mgroves on Twitter, the C# Advent site, and this very blog for announcements when the calendar gets toward the last third.

Thank you Smashing Magazine for featuring the C# Advent in your Advent Calendars For Web Designers And Developers (December 2021 Edition) round-up.

Thank you Sergey Tihon for the inspiration.

A special extra thanks to Calvin Allen, who does a lot of behind-the-scenes work on C# Advent (including the domain name, LinkedIn, the new CsAdvent twitter account, testing, and much more) AND writes an Advent entry AND deserves accolades for all of it!

Welcome to day 16 of the 2021 C# Advent! Make sure to check out all the other great Advent items that have been opened so far!

I have been working on an experimental tool called SqlServerToCouchbase. The goal is to help people automate their relational data moving and refactoring into a Couchbase JSON database as much as possible.

It is a .NET library that you can use (in, for example, a console project). It maps a relational concept like "table" to a NoSQL concept of "collection" (among other things). Couchbase is particularly suited to this, because Couchbase also supports SQL as a querying language (with JOINs / ACID / INSERT / UPDATE / etc), and has supported SQL for many years. If that sounds interesting to you, I’d love for you to leave your feedback, criticisms, suggestions, and even pull requests on GitHub.

What I want to focus on today, however, are three great .NET libraries that I used to help build SqlServerToCouchbase. Three wise gifts: SqlServer.Types (gold), Dynamitey (frankincense), and Humanizer (myrrh).

dotMorten.Microsoft.SqlServer.Types (Gold)

The gift of gold signified that the receiver was as important as a king.

Gold

SQL Server has many data types. Mapping these data types into C# types (and ultimately to JSON) is usually straightfoward.

  • varchar, nvarchar, text? string.

  • int, float, decimal, money? number.

  • bit? boolean.

  • Even XML can become a string.

But what about the other types? Spatial types, mainly: Geography and geometry? That’s what Microsoft.SqlServer.Types is for: to provide C# types that can store propietary SQL Server data type values.

However, notice the "dotMorten" part of the library name? Unfortunately, the official Microsoft.SqlServer.Types library is not a .NET Standard library. So, Morten Nielsen created the dotMorten.Microsoft.SqlServer.Types library.

There’s a code example below, but you won’t see the library in action explicitly.

// SqlServerFrom.cs
public IEnumerable<dynamic> QueryBulk(IDbConnection conn, SqlPipelineBase pipeline)
{
    return conn.Query(pipeline.Query, buffered: false);
}

// SqlToCb.cs
foreach(var row in rows)
{
    // ... snip ...
    await collection.UpsertAsync(documentKey, row);
    // ... snip ...
}

I use Dapper to query SQL Server data, store those results in C# dynamic objects, and then give those objects to the Couchbase .NET SDK (which ultimately serialized it to JSON).

That means that a row of SQL Server data, like this:

SELECT a.AddressID, a.SpatialLocation
FROM AdventureWorks2016.Person.Address a
WHERE a.AddressID = 1

Row of SQL Server data

Gets transformed into a Couchbase JSON document like this:

SELECT a.AddressID, a.SpatialLocation
FROM AdventureWorks2016.Person.Address a
WHERE a.AddressID = 1;
[ {
    "AddressID": 1,
    "SpatialLocation": {
      "HasM": false,
      "HasZ": false,
      "IsNull": false,
      "Lat": 47.7869921906598,
      "Long": -122.164644615406,
      "M": null,
      "STSrid": 4326,
      "Z": null
    }
} ]

So, even if a SQL Server database is using one of these less common data types, SqlServerToCouchbase can still move it.

Dynamitey

The second gift is frankincense. This is an expensive incense fit for a holy king.

Frankincense

Another challenge of SqlServerToCouchbase is getting the value of the primary key. In Couchbase, a document key exists as a piece of "metadata" about the document. However, in SQL Server, a primary key consists of one (usually) or more (uncommon) fields in a table. These fields can have ANY name. Usually it’s something like "ID", "AddressID", "ADDRESS_ID", etc. But it can vary from table to table.

Once I know the names of the fields, I need to examine the dynamic object to get the values of those fields. This is where I use Dynamitey.

Dynamitey is a utility library that provides extensions to the DLR, including:

  • Easy Fast DLR based Reflection (what I’m using it for)

  • Clean syntax for using types from late bound libraries

  • Dynamic Currying

  • Manipulation of Tuples

And more.

Key names can be retrieved from SQL Server by querying INFORMATION_SCHEMA.KEY_COLUMN_USAGE. I can use those names to get the values like so:

// append key values together with :: delimeter
// for compound keys
var keys = await _config.GetPrimaryKeyNames(tableSchema, tableName, _dbFrom);
var newKey = string.Join("::", keys.Select(k => Dynamic.InvokeGet(row, k)));

If a primary key is made up of one column and the row has a value of "1", then that becomes the document key in Couchbase. If a primary key is made up of multiple columns, with values of "123" and "456", that becomes a document key in Couchbase of "123::456".

If it weren’t for Dynamitey, I’d have to create C# classes for every table. And that greatly reduces the amount of automation.

Humanizer

The third gift is myrrh. Another expensive gift. This one is fit for a holy, but also human king.

Myrrh

Humanizer is a .NET library that manipulates string, dates, numbers, etc, for display to a human. There are many things it can do, but I use it for pluralization.

When making the transition from relational to Couchbase, one of the things you must consider is when to embed data into documents. For instance, in relational, you may have two tables (Person and EmailAddress) in order to support a situation where a person has more than 1 email addresses.

SELECT p.BusinessEntityID, p.FirstName, P.LastName
FROM AdventureWorks2016.Person.Person p
WHERE p.BusinessEntityID = 1

SELECT e.EmailAddress
FROM AdventureWorks2016.Person.EmailAddress e
WHERE e.BusinessEntityID = 1

Relational modeling

(In this example, there’s only 1 email address, but the model supports more).

In a document database like Couchbase, it’s often preferable (though not required) to embed those email addresses into an array in the person document. Something like:

{
  "BusinessEntityID" : 1,
  "FirstName" : "Ken",
  "LastName" : "Sánchez",
  "????" : [
    { "EmailAddress" : "[email protected]"}
  ]
}

But what do I put into the "????" in that JSON? If I use the name of the table ("EmailAddress"), that implies that there’s only one. I would rather it be called "EmailAddresses". Hence, I use Humanizer to pluralize it:

spec.ArrayAppend(From.TableName.Pluralize(), docToEmbed.ContentAs<dynamic>(), true);

So, now it becomes:

{
  "BusinessEntityID" : 1,
  "FirstName" : "Ken",
  "LastName" : "Sánchez",
  "EmailAddresses" : [
    { "EmailAddress" : "[email protected]"}
  ]
}

Thanks for checking out these three libraries! I hope these will help you some day. Don’t forget to check out the rest of the 2021 C# Advent.

What is the C# Advent?

The C# Advents in 2018 and 2017 were so much fun. It's now time to sign up for 2019.

Just like last year, each day of the Advent calendar will have up to TWO blog posts. That means that there is a maximum of FIFTY slots! So, tell your C# friends and let's fill up this calendar.

A little history: I heard about the F# Advent Calendar, a tradition that's been carried on since 2010 (2014 in English). I think this is a great idea, and so I organized one for C#! (I asked Sergey Tihon for permission!). If you are running other developer advent calendars, just let me know and I will link to them here:

Let's Get Started

I need you to write a C# blog post, create a video, write an article, etc.

Here are the rules:

  1. Reserve a slot on Twitter (with hash tag #csadvent) or leave a comment on this post. You do not have to announce your topic until the day you reserve.
  2. Prepare your content (in English).
  3. Add a link in your content that links back to here, so that your readers may find the entire advent. You can host your content anywhere you'd like: your own site, dev.to, hackernoon, medium, wordpress, youtube, dzone, etc.
  4. Publish your content on the specified date. Your content must be related to C# in some way, but otherwise the content is completely up to you. I've posted a few ideas below to get your creativity flowing.
  5. Share your post on Twitter with hashtags #csharp and #csadvent

Below are all the slots, and who has claimed each date.

I will do my best to keep this up to date. The slots will be first come first serve. I also allowed last year's authors to get first crack. I will claim the last remaining spot for myself. I will prepare a post just in case someone has to drop out.

DateClaimed byContent
Dec 1, 2019 Brant Burnett Simon Painter  IAsyncEnumerable Is Your Friend, Even In .NET Core 2.x Hacking C#: Programming for the Truly Lazy
Dec 2, 2019 Luis Antonio Beltran Chris Ayers 2FA with Twilio Authy and C# (special guest: Xamarin) Dependency Injection, Architecture, and Testing
Dec 3, 2019 Kelson Ball Morgan Kenyon An Example of Partial Function Application in C# The Difference Between IEnumerable and IQueryable Explained
Dec 4, 2019 Ryan Overton Carl Layton Default Interface Methods in C#: Love 'em or Hate 'em? The Outbox Pattern in C#
Dec 5, 2019 Dave Cook Manuel Grundner To Null, or not to Null?!? The journey of porting pretzel to .NET Core
Dec 6, 2019 Lukáš Lánský Simon Timms Coverage-Driven Test Selection Machine Learning for Boring Applications
Dec 7, 2019 Chase Aucoin Kendall Miller Aurora Serverless with Entity Framework Core Better String Formatting with String Interpolation
Dec 8, 2019 Matt Eland Jeremy Sinclair Experimental C# with Scientist .NET Creating a Simple Wizard Component with Blazor
Dec 9, 2019 Meziantou Cecilia Wirén Thread-safe observable collection in .NET Overflow on integers - count with this security risk!
Dec 10, 2019 Andrew Lock James Hickey .NET Core, Docker, and Cultures - Solving a culture issue porting a .NET Core app from Windows to Linux Modular Monoliths And Composite UIs With .NET Core Razor Class Libraries
Dec 11, 2019 DotNetCoreShow Roman Stoffel The .NET Core Podcast - Episode 40 - Noda Time with Jon Skeet C# Loves Code Patterns
Dec 12, 2019 Brian Jackett James Curran Creating a C# Azure Function to Call Microsoft Graph Cleanup Scaffolded Code with modelbuild
Dec 13, 2019 Barret Blake Ed Charbeneau, Daniel Roth, Chris Sainty, Egil Hansen The Nightmare Before Blazor Getting Started with Blazor: All There is to Know From the Experts
Dec 14, 2019 Benjamin Howarth Martin Zikmund   A Christmas C# riddle
Dec 15, 2019 Jonathan Danylko Hilary Weaver-Robb 10 More Useful C# Extension Methods for 2019 Refactoring RestSharp Sample Tests to Make Them More Maintainable
Dec 16, 2019 Shahed Chowdhuri Ian Bebbington ASP .NET Core code sharing between Blazor, MVC and Razor Pages The Seven GUIs of Christmas
Dec 17, 2019 Joe Zack Chris Sainty Streaming process output to a browser, with SignalR and C# Introduction to Blazor Component Testing
Dec 18, 2019 Garo Yeriazarian Stuart Turner Vertically Sliced Command Line Tools in C# and .NET Core 3.1 Improving Code Readability with Linq (and MoreLinq)
Dec 19, 2019 Baskar Rao Stephen Lorello How to use Subscriptions in GraphQL C# Santa’s Nexmo Helper
Dec 20, 2019 Andrea Angella Layla 15 reasons why you should learn C# in 2020 Get off the naughty list with Twilio Autopilot, Azure Functions and Table Storage
Dec 21, 2019 Muhammad Azeez Patrick Lioi How do Object Relational Mappers (like Entity Framework) work? Patterns for using Entity Framework in C# 8
Dec 22, 2019 James Bender Eric Potter Refactoring for Testability – A Christmas Miracle! C# Strings with Ranges, and Indexes
Dec 23, 2019 Andrew Craven Lee Englestone Microservices and Outside-in Tests Using C# and Docker Compose Compiling Code without Visual Studio
Dec 24, 2019 Thomas Carpe Azmat Ullah Khan   PDF Digital Signatures with Itext7, Bouncy Castle and .NET Core
Dec 25, 2019 Mike Jolley Calvin Allen Adding HATEOAS to an ASP.NET Core API C# 8 is old news. Onward, to C# 9!

Alternates:

  • IF ALL FIFTY SLOTS FILL UP, please leave a comment or tweet with #csadvent anyway and I'll put you on this standby list:
  • Standby list:
    • Myself.
    • You, if you want to be.

Some ideas/topics to help inspire you:

  1. Blazor - C# for the browser
  2. Your latest open source contribution - show the community how you contributed and why
  3. Your favorite C# language feature - it doesn't even have to be a new feature, just blog about something you love about C#
  4. Introduce your favorite NuGet package / library. Even if it's a library you take for granted, not everyone has heard about it.
  5. How to avoid a pitfall you found with performance/memory/etc
  6. Integration/deployment of a C# application with Jenkins, Docker, Kubernetes, TeamCity, Azure, etc
  7. Write a "how to" for one of the many tools discussed in an episode of the Cross Cutting Concerns podcast or the DotNetBytes podcast
  8. Interview someone about C# and post the audio or a transcript.
  9. Implement a simplified example of a design pattern in C#

Thanks to everyone who is participating!

If you were an author of a C# Advent blog post in 2018, you get a chance to sign up earlier than the general public.

Tweet #csadvent or leave a comment below with the date you want to blog on. Each day has up to TWO slots. If someone has already claimed the day you want, that day may still be available.

The general call for C# Advent authors will go out soon, so please claim your dates as soon as possible. Just like last year, you do NOT have to pick a topic right now. If you DO want to pick a topic, I will pencil it in, but you are free to change it at any time up until the date you pick.

Matthew D. Groves

About the Author

Matthew D. Groves lives in Central Ohio. He works remotely, loves to code, and is a Microsoft MVP.

Latest Comments

Twitter