Skip to content

Instantly share code, notes, and snippets.

@ManojLingala
Last active June 17, 2018 20:33
Show Gist options
  • Save ManojLingala/d54cadcd5b4a2b495866e5ace99a09d7 to your computer and use it in GitHub Desktop.
Save ManojLingala/d54cadcd5b4a2b495866e5ace99a09d7 to your computer and use it in GitHub Desktop.
FullStackDotnetDevonMac

Microsoft Developer's who loves to code on Macbook will always dreamt of FullStack .NET development on Mac. Finally , {DotNET, ASP.NET} Core were officially released and SQL Server recently got support for Linux and Microsoft has now published a Docker image for SQL Server for Linux, you can now run SQL Server on Mac via Docker!

First of all, even with all these in place due to the lack of the quality tools which slow down the development phase. So, I'm writing this to provide a step by step process of setting up Development env on Macbook with proper tools which increases the productivity and efficiecy .

  1. Install Visual Studio Community Edition for Mac https://www.visualstudio.com/vs/mac/

  2. Install Docker Download the (free) Docker Community Edition for Mac (unless you’ve already got it installed on your system). This will enable you to run SQL Server from within a Docker container https://docs.docker.com/docker-for-mac/

  3. Configure Docker by increasing the Memory

    By default, Docker will have 2GB of memory allocated increase it to 4GB to be at a safer side as SQL Server needs atleast 3.5 GB.

  4. Download Sqlserver 2017 Open a Terminal window and run the following command.

    docker pull microsoft/mssql-server-linux

    Alt text

  5. Launch the Docker Image

    sudo docker run -d --name containername -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=reallyStrongPwd123' -e 'MSSQL_PID=Developer' -p 1433:1433 microsoft/mssql-server-linux:2017-latest

    You should now have SQL Server running on your Mac, ready for action!

    Alt text

    If the STATUS column for your SQL Server container shows Exited . see the troubleshooting guide https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-configure-docker?view=sql-server-linux-2017#troubleshooting

    Better Managing the Docker Image's :

    Get Kitematic

    Kitematic is a nice desktop application for managing Docker containers. The first time you click Open Kitematic, it will prompt you to download and install it. You can then use Kitematic to view the output of your containers, manage their settings, logging, etc.

    Alt text

  6. Connect to SQL Server

    Get the SQL Operations Studio it is a data management tool that enables working with SQL Server, Azure SQL DB and SQL DW from Windows, macOS and Linux. https://docs.microsoft.com/en-us/sql/sql-operations-studio/download?view=sql-server-2017

Alt text

Now the Development environment is all set up . It's time to test it with the below cheeky code

using System;
using System.Collections.Generic;
namespace Domain
{
public class Battle
{
public int Id { get; set; }
public string Name { get; set; }
public DateTime StartDate { get; private set; }
public DateTime EndDate { get; private set; }
public List<Samurai> Samurais { get; set; }
}
}
using System;
namespace Domain
{
public class Quote
{
public int Id { get; set; }
public string Text { get; set; }
//Ref back to Samurai
public Samurai Samurai { get; set; }
public int SamuraiID { get; set; }
}
}
using System;
using System.Collections.Generic;
namespace Domain
{
public class Samurai
{
public Samurai()
{
Quotes = new List<Quote>();
}
public int Id { get; set; }
public string Name { get; set; }
public int BattleId { get; set; }
public List<Quote> Quotes { get; set; }
}
}
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Domain;
namespace Data
{
public class SamuraiContext : DbContext
{
public DbSet<Samurai> Samurais { get; set; }
public DbSet<Battle> Battles { get; set; }
public DbSet<Quote> Quotes { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
// Configure your Connection string
optionsBuilder.UseSqlServer("Data Source=127.0.0.1,1433; Initial Catalog=SamuraiDB; User ID =SA; Password =reallyStrongPwd123;");
}
}

Install NUGET CLI https://docs.microsoft.com/en-us/nuget/tools/nuget-exe-cli-reference

Install .NET SDK https://www.microsoft.com/net/learn/get-started/macos

Install Microsoft.EntityFrameworkCore.Tools.DotNet https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.Tools.DotNet/2.1.0-preview1-final

Add Migration

ef --startup-project ../CoreUI migrations add init

Alt text

Execute the DB

dotnet ef --startup-project ../CoreUI database update

Alt text

Easily all the above mentioned instructions can be automated .

Happy Coding .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment