Introduction

In case you missed the other days:
Day 1 Deep Dive
Day 2 Deep Dive with MongoDB

As mentioned in last night's post tonight I will be adding in the SQL Server/WebAPI comparison to the MongoDB/Node.js work I did last night.

Prerequisites

If you're coming from a C# background you probably already have SQL Server 2016 Express, but in case you don't you can download it here.

SQL Server setup

Knowing SQL Server got JSON Storage options and is arguably the best relational database available, I wanted to try both a traditional relational test and a JSON/Document storage test.

For the traditional test I executed the following SQL:

CREATE TABLE POSTS (  ID int PRIMARY KEY NONCLUSTERED,   Likes INT )

WebAPI/EntityFramework Core

With EntityFramework Core coming out of RC back in June I wanted to utilize it as opposed to the now "legacy" 6.x version most C# developers have gotten used to.

For this demo I chose to use a Code First Approach, defining my POCO as such:

public class Posts { [Key] public int ID { get; set; } public int Likes { get; set; } }

The actual Entity Framework saving code is as follows:

[HttpGet] public async Task Get(int id) { var post = new Posts { Likes = id }; _context.Posts.Add(post); await _context.SaveChangesAsync(); return "OK"; }

In addition I am utilizing the DI built into ASP.NET Core by adding in a call inside the startup.cs:

public void ConfigureServices(IServiceCollection services) { var connection = @"Server=localhost;Database=DayInNode;user id=sa;password=raptor;"; services.AddDbContext(options => options.UseSqlServer(connection)); services.AddMvc(); }

Performance

Just comparing a traditional relational approach to MongoDB I figured would be dramatically different considering how much faster Node.js handled requests, however even after running multiple tests it was pretty even:


Next up...

Tomorrow I hope to try this same test, but with the new JSON/Document Storage option that SQL Server 2016 added.
Lastly, all of the code thus far is committed on GitHub.
TAGS
none on this post