Notes on things a (hopefully) useful collection of knowledge

(Re-)Learning c# for fun (and profit?)


Dotnet interactive as a rails-console replacement

The tool I miss most when not using ruby-on-rails (which I use at my day-job) is the rails console. My main use for the console is to write queries in the same ORM language as the rest of my application. For example, I might drop into the rails console to see the raw output of a query like Course.where('start_date < DateTime.now - 1.year'). Or, if I need to create some fake data, I could drop into another console and run something like Course.last.update(start_date: DateTime.now - 2.year). Both of these would be easy enough to do in SQL, but I find it more convenient to use the application’s ORM and have access to any helper functions that I’ve already written.

Recently, I’ve tried to approximate this workflow using dotnet interactive, and I’ll describe that setup below. The finished result can be found here(github).

Notebook example

Read More…

Configure Await

Reading through a asp.net core project, I came across number of calls that looked like this:

int affectedRows = await this._context
    .SaveChangesAsync()
    .ConfigureAwait(false); // ME: what does this do?
return affectedRows;

I dug into what this was actually doing by reading this blog:

  • await uses a custom callback strategy based on the calling context
  • ConfigureAwait(false) ignores the custom strategy.

Dotnet query console

As I’ve developed with Rails, the feature I’ve come to appreciate the most is the rails console. It gives you an immediately connected view into your application - fully hooked up to all of your code and to your database.