.NET Workbooks: Entity Framework Model Explorer

Akos Nagy
Feb 28, 2017

I've been a long time follower of Scott Hanselman. I mean, who hasn't? The guy has a very good sense of technology and has some great insights about .NET stuff, but beyond that, he has a special attitude towards life in general (as far as I can tell from the few op-ed-like posts). Check out his most popular articles — trust me, one way another, at least a few of those are going to change the way you think about your job and hopefully, your craft.
A couple days back he posted a review about this great new tool called Xamarin Workbooks. I'm not going to the intricate details (you can check out either Mr. Hanselman's post or the product website for that), but here's my short impression.

Xamarin Workbooks is basically an interactive learning tool. Just like a regular workbook, you can make notes in it. Now if you've ever taken a programming class where you were forced to listen to useless ppt presentation for a semester long without any actual coding (trust me, I have), you probably have some notes at home which comprise of two "sections": you have code sections and you have explanatory sections. You write a piece of code onto the paper, then in the next paragraph you make some notes about what that code would do if you ran it, how it works, what to watch out for etc.

This is all nice, but if you're like me, after a class like this, you go home, you type your code in and actually run it. Just to see at least the results. But this is kinda boring; for one, you have to sit through a coding class without actual coding, then go home and do the actual coding. How awesome would it be if you could run the parts in your workbook which contain code? Well, Xamarin workbooks let's you do just that.

You can define document sections, where you can write explanations, and you can define code sections, which contain your code. And you can actually run the code in the code sections. The sections have an implicit reference to the previous section, thus making one big piece of code. You can check out the results of each section. It's awesome. Oh, and under the hood it's all just Markdown, so if you're like me and have a blog and use Ghost (or any other Markdown-based platform) you can convert your posts to workbooks quite easily.

Even better, this is not just for Xamarin. There is a host of hosts (yeah I know, but I haven't slept for a while) that you can choose from: Console, WPF, iOS and Android. So basically this is not just for mobile developers, these are for every .NET developer. I completely agree with Mr. Hanselman, that they are rather .NET workbooks, with a Xamarin option.

And even better, you can extend it with your own result visualizers and own API-s that can be used inside the workbook. If you have read my previous posts (like this one or this one) you might know that I'm a Microsoft Certified Trainer and I teach a lot. The moment I tried this I knew that this was something that would benefit my students a lot and started thinking about ways to incorporate it into my classes. To be honest, I was kind of ashamed that I hadn't know about this before.

So there I was thinking about the best ways to use this in class. I had to be careful though. This is not something you can work in, so if you want to give real, useful knowledge (you know, "working-knowledge") to people, you have to use Visual Studio. But still, in some cases, this can be useful.

Now if you've read some of my posts (like this one or this one) you probably know that I love Entity Framework. Code First, mostly. When I teach people about EF CF, I spend quite some time on building your model, explaining the different options and presenting how those options affect the underlying database.

So I created a workbook with my own API and visualizers to help demonstrate this. There is some explanation in it, a sample how to use the API and also a sample on how to do the actual model exploration.

To get the create scripts I took the answer from this SO post and modified it a bit (I mean, who needs collation when we're using EF? I'm guessing none of us have ever spent half a day trying to track an bug only because the default collation of the db was case-insensitive and we're so used to C# case sensitive strings...) and to create the accordion, I used this W3Scool tutorial. (Yes, I basically Googled a lot and repackaged the whole thing :) ).
If you like the idea and would like to try the workbook, you can download it from here. If you'd like to use it in class maybe, even better, just give me a shout-out in the comments.

Akos Nagy