Chris Padilla/Blog
My passion project! Posts spanning music, art, software, books, and more
You can follow by Newsletter or RSS! (What's RSS?) Full archive here.
- Run a DB locally
- Setup our DB Schema through the Models of our application, not in SQL
- Setup migrations for our application to keep the SQL Schema in sync with our models
[Key]
is a Data Annotation that lets Entity Framework know that this is our Primary Key in SQL[Required]
does as you'd expect. One thing worth noting: to avoid a non-null error, set the Name value in the constructor.- Tolkein's Fellowship of the Ring Wow, the "One does not simply..." meme doesn't actually come up in the book! Nor does "You have my bow...and my axe!"
- Calvin and Hobbes Vol. 1 These strips are so delightfully dynamic! I can't believe I've slept on these.
- Mickey Mouse, Vol. 2: Trapped on Treasure Island A find at Recycled Books in Denton. The adventure strips from the 30's are so wildly detailed!
- I have a few words written through the Books tag on my blog. My favorite this month: Rob Ingles Singing Lord of the Rings
- Rooms With Walls and Windows by Julie Byrne. Beautiful, moody, home grown solo album.
- This Jungle in Gaming Mix on YouTube is a special kind of nostalgic.
- program music II by KASHIWA Daisuke. Is "Music That Could Be in an Anime Movie" a genre?
- Ted Lassoooooo! 💔
- I'm listening to Cartoonist Kayfabe while I draw. Since comics are a solitary experience, it's so fun to hear a couple of pros geek out over them together!
Calvin in the Tree House
Dvorak — New World Finale
So TRIUMPHANT! 🌅 💪
Database Setup and Migrations for Microsoft SQL Server and ASP.NET Core MVC
I know this is old news at this point, but using Microsoft products on Mac (let alone an M1 machine!) is a wild concept to me! It's in the same vein as Superman & Batman in the same movie, or Mario and Sonic in the same game.
I'm getting familiar with ASP.NET Core 6.0 MVC. I've been able to get things up and running with primarily native solutions, much to my surprise! There are a few different paths I've had to take to get all the way, though.
The tl;dr: For .NET, favor the dotnet
CLI over the Visual Studio GUI. For SQL, Docker is your friend.
To expand on it, here's how I handled getting my local environment set up to run a local Microsoft SQL Server for my web app:
Overview
The ultimate goal here is:
Here we go!
Running Microsoft SQL Server Locally
The solution on Windows for interacting with the Database is Microsoft's SQL Server Management Studio (SSMS). For Mac and Linux, we'll have to opt for Azure Data Studio.
That takes care of the GUI.
For running a server, this guide gets you most of the way there.
The caveat is that on M1, there's not great support for the image mcr.microsoft.com/mssql/server:2022-latest
.
Instead, grab the Azure image:
$ docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=YOURGENERATEDPASSWORD" -p 1433:1433 -d mcr.microsoft.com/azure-sql-edge:latest
The -e "ACCEPT_EULA=Y"
is important for accepting the terms and conditions before running.
The rest of the guide will take you through connecting to Azure Data Studio!
Creating Models
Assuming you already have an app template running, we'll add a new Model called "Book" to our project:
// Book.cs
using System;
using System.ComponentModel.DataAnnotations;
namespace LibraryMVC.Models
{
public class Book
{
[Key]
public int Id { get; set; }
[Required]
public string Name { get; set; }
public int isbn { get; set; }
public DateTime CreatedDateTime { get; set; } = DateTime.Now;
public Category(string name)
{
Name = name;
}
}
}
A quick run down of some interesting points:
That's all there is to setting up the Schema!
Migrations
If you're used to MongoDB, this is where you would call it a day for setting up the schema. MongoDB doesn't require any enforced schema at the database level.
With SQL, however, we do have more setup to do there.
The excellent thing about this approach, coming from Express and Mongo, is that largely, the source of truth is still in our application. We'll simply setup a migration for SQL to mirror the schema from our Model.
A deeper Migrations Overview from MS is available on their site. For us, let's get into the quick setup:
First, ensure you have the dotnet
CLI installed.
We'll use it to install the Entity Framework tool globally:
dotnet tool install --global dotnet-ef --version 6.0.16
With that, you can then run this command to migrate:
dotnet ef migrations add AddBookToDatabase
AddBookToDatabase
is what the migration will be named. You can call it whatever you like.
You may need to install extra Nuget packages before the command goes through:
Your startup project 'LibraryMVC' doesn't reference Microsoft.EntityFrameworkCore.Design. This package is required for the Entity Framework Core Tools to work. Ensure your startup project is correct, install the package, and try again.
With the SQL server connected, Entity Framework will look at the models in your app, compare what's in the DB, and create the DB with appropriate tables and columns based on your models directory.
To verify all worked, you can check Azure Data Studio for the data, and look for a "Migrations" folder at the root of your application.
And that's it! All set to fill this library up with books! 📚
The Haps - June 2023
Summer time!!!
Blogging & Dev
Taking a slower pace with blogging, but still sharing my adventures in C# and .NET!
You can catch up with my tech projects through the Tech tag on my blog.
Music
I released Forest a while back! An experiment in playing with a few sounds from Ocarina of Time and Chrono Trigger!
I'm digging deep into learning finger style guitar. My favorite so far was this cowboy waltz I improvised on my new acoustic.
You can see what I've shared so far through the Music tag on my blog. I'm also sharing recordings on Instagram.
Drawing
I finished my fourth sketch book! I'm starting to not treat them as precious and am really drawing loosely in them. It's great, very liberating!
My routine at the moment is studying other artists, drawing from imagination, and doing perspective / figure drawing exercises. Both from Proko and drawabox.
You can see what I've made so far through the Art tag on my blog. I'm also sharing drawings on Instagram.
Words and Sounds
📚
🎧
📺
Life
It's hot. I'm cold blooded. So I'm in my element! ☀️
Had my folks visit for Mother's day!! We had a good time exploring a few museums in Dallas and eating good food.