Microsoft Insider Dev Tour in Manchester

This week saw Manchester hosting one of the Insider Dev Tours of 2018, we had a great turnout of over 100 people joining us in the city centre, for a full day of content with lunch provided by Microsoft.

These are over thirty events being hosted in cities all over the world and are aimed at developers and IT pro’s who are on the Windows Insider Programme and/or are interested in seeing what features and enhancements are being shipped in the latest and next versions of Windows 10.
The events are run by local MVP’s (Most Valuable Professionals) and community groups with the content and demos provided by Microsoft, so it’s an intensive lap around the key features that Microsoft want to highlight for 2018 and based on sessions provided at last month’s Build conference in Seattle.

I did two sessions, one on Progressive Web Apps and one on Productivity Apps in Office365 and there was a host of MVP talent on show for the others – Pete Vickers, Peter Foot, Rob Miles, Robert Hogg, Rik Hepworth and Simon Jackson.

A big thanks to Pete Vickers, who put in a load of work to make the day the success it was, and also to Aden Earnshaw and Mike Irving, who gave their time running the registration desk and generally doing the unsung heroics on front of house.

If you want to follow any of the labs from the sessions, they are available here.

The robots are coming with cheese!!

Last month saw us meeting once again at Auto Trader for May’s DotNetNorth. We welcomed our old friend Rob Miles over from Hull to talk about his latest passion, dinky robots! Rob has been working on these things for a while and opened with a description of how he designed a little robot using stepper motors, Arduino boards and various sensors (after, of course, a couple of corny opening gags).

Rob has conceived these robots – called Hull PixelBots officially – to be easy to build with off-the-shelf (cheap) electrical components and even a 3d-printable chassis (although you can just use perspex or balsa wood). He has also written the operating system that powers the beasts called HullOS (are you detecting a theme here?); but is adamant that that sounds much harder than it actually is.

Rob then showed us a few demos and explained that using a few of the features in Azure, he could control the beasts remotely. If you want to see the presentation, it was recorded by our friends from Pusher – you can find it here

Global Azure Bootcamp in Manchester

Last Saturday a group of community group leaders and helpers in Manchester joined forces with hundreds of other people for the 2018 Global Azure Bootcamp run in association with Microsoft. At the event we had four sessions covering various parts of the Azure ecosystem, some with hands-on labs so people could get a good feel how Azure solutions come together.

So huge thanks to our session leaders who came together and devise an agenda in just a couple of weeks:
Luce Carter, organiser of the Xamarin user group who did our Intro to Azure and using the portal session.
Aden Earnshaw, who did a great job on his user group presenting debut and covered Web Apps.
Martin Boam, who recently was awarded a Microsoft MVP award and runs the Cloud User Group gave a session on Serverless computing.
Jim Bennett – a Cloud Developer Advocate at Microsoft – came all the way from Reading and delivered a great demo about using Azure AI to augment mobile apps, despite the curse of the demo gods striking!
(And I did one on CosmosDB / DocumentDb too)

We also thank Auto Trader for providing the venue for us and providing coffee and tea for the whole day – especially Helen, the venue event co-ordinator who is always helpful.

This was our first go at running the Bootcamp, it was hectic but very rewarding to work with some new people in the run up and to see everyone learning something new on the day – hopefully we will be doing another one next year too! But I won’t be thinking about it too hard for a couple of months.

Using Table Valued Parameters in Dapper

Today I discovered a neat way of passing values into a SQL Server stored procedure with Dapper using a Table Valued Parameter. Up to now, I’d been using a DataTable, adding the columns programatically and then populating it row-by-row. Whilst re-reading Erland Sommarskog’s detailed post about dynamic SQL, I noticed something I hadn’t picked up on before – that there was another way of doing this. Some more research via Leonard Lobel’s site lead me to this solution, which is much neater that the DataTable shenanigans.

Firstly we need to create a table-valued parameter in SQL Server: In your database, open a new query and type:

CREATE TYPE dbo.SimpleKeyList AS TABLE( [KeyId] INT NULL)

Next we create a procedure that will accept the TVP as a parameter:


CREATE PROC dbo.EchoKey
@KeyList dbo.SimpleKeyList READONLY
AS
SELECT KeyId FROM dbo.SimpleKeyList ORDER BY KeyId DESC

This procedure will just return all the keys sent in but in reverse numerical order, so we can see that some processing has occurred.

Now we need to do a bit with Dapper;

This is our basic method:


        public List<int> EchoSomeKeys(KeyList inputData)
        {
            using (var db = new SqlConnection(_connString))
            {
                var data = db.Query<int>("EXEC Core.EchoKey @KeysIn", 
                    new {KeysIn = inputData.AsTableValuedParameter("dbo.SimpleKeyList") }
                );
                return data.ToList();
            }
            
        }

Looks simple doesn’t it? Now all we need is our input class KeyList:


public class KeyDto
{
    public int KeyId { get; set; }
}
public class KeyList : List<KeyDto>, IEnumerable<SqlDataRecord>
{
  IEnumerator<SqlDataRecord> IEnumerable<SqlDataRecord>.GetEnumerator()
  {
    var sdr = new SqlDataRecord(new SqlMetaData("KeyId", SqlDbType.Int));

    foreach (KeyDto item in this)
    {
      sdr.SetInt32(0, item.KeyId);
      yield return sdr;
    }
  }
}

You can see that a little bit of magic is injected via the implementation of

IEnumerable<SqlDataRecord>

Dapper provides the AsTableValuedParameter method which iterates over the enumerator provided by the interface and populates the parameter TVP.

I knocked up a quick NUnit test to check it all works:


[TestFixture]
public class TestTableValuedParam
{
  [Test]
  public void TVP1()
  {
    var a = new Tvps();
    KeyList keysIn = new KeyList();
    keysIn.Add(new KeyDto { KeyId = 68});
    keysIn.Add(new KeyDto { KeyId = 12 });
    keysIn.Add(new KeyDto { KeyId = 42 });

    var m= a.EchoSomeKeys(keysIn);
    Assert.That(m.Count, Is.EqualTo(3));
    foreach (var i in m)
    {
      Console.WriteLine(i);
    }
  }
}

Which verifies that we get the values returned in reverse order.