25 Sept 2019

How to add Entity Framework Core into ASP.Net Core project

Installation

1. Open a terminal and navigate into the project's folder
2. Use the following .NET Core CLI command from the operating system's command line to install or update the EF Core SQL Server provider

Global EF installation

dotnet ef must be installed as a global or local tool. Most developers will install dotnet ef as a global tool with the following command:

dotnet tool install --global dotnet-ef

https://docs.microsoft.com/en-us/ef/core/get-started/?tabs=netcore-cli

=============

Project

for MS SQL
dotnet add package Microsoft.EntityFrameworkCore.SqlServer

or for SQLite
dotnet add package Microsoft.EntityFrameworkCore.Sqlite 

modifier
-v // version
-v 2.2.0

3. Install tools to carry out EF Core-related tasks in your project, like creating and applying database migrations, or creating an EF Core model based on an existing database

dotnet add package Microsoft.EntityFrameworkCore.Design

For ASP.NET Core apps, this package is included automatically. Database provider design-time packages such as Microsoft.EntityFrameworkCore.SqlServer.Design are no longer required or supported from EF Core 2.0 and later, but aren't automatically removed when upgrading the other packages

4. To get the Package Manager Console tools for EF Core, install

dotnet add package Microsoft.EntityFrameworkCore.Tools


or install packages via NuGet

=============

Add Migrations

After you've defined your initial model, it's time to create the database. To add an initial migration, run the following command:

dotnet ef migrations add InitialCreate 

Update the database
Next, apply the migration to the database to create the schema.

dotnet ef database update

Remove a migration
Sometimes you add a migration and realize you need to make additional changes to your EF Core model before applying it. To remove the last migration, use this command. After removing the migration, you can make the additional model changes and add it again.

dotnet ef migrations remove

Revert a migration
If you already applied a migration (or several migrations) to the database but need to revert it, you can use the same command to apply migrations, but specify the name of the migration you want to roll back to.

dotnet ef database update LastGoodMigration

=============

Commands

dotnet ef migrations add
dotnet ef migrations list
dotnet ef migrations script
dotnet ef dbcontext info
dotnet ef dbcontext scaffold
dotnet ef database drop
dotnet ef database update


24 Sept 2019

Getting started ASP.NET Core (Web API Project)

1. Install .NET Core SDK

2. Test
dotnet --version

3. Create project from a template
dotnet new webapi -o myApp

or

dotnet new webapp -o myWebApp --no-https

The -o parameter creates a directory named myApp where app is stored

4. Navigate into the project's folder and run
dotnet run

Additional

Run the following commands to install the required packages

dotnet restore

How to use Visual Studio Code to manage MSSQL Databases

1. Install the mssql extension for VS Code
2. Create or open a SQL file
3. Connect to SQL Server
-- Press Ctrl+Shift+P or F1 to open the Command Palette.
-- Start to type MS SQL and select MS SQL: Connect from the dropdown
--- MS SQL: Manage Connection Profiles
--- Then select Create
--- Follow the prompts to specify the properties for the new connection profile. After specifying each value, press Enter to continue.

5. Run the SQL script to test it.

CREATE DATABASE AppDB
GO

EXEC SP_HELPDB AppDB;

USE AppDB;

CREATE TABLE [User]
(
UserId int NOT NULL PRIMARY KEY IDENTITY,
FirstName [NVARCHAR](50) NOT NULL,
LastName [NVARCHAR](50) NOT NULL
);
GO

INSERT INTO [User]
(FirstName, LastName)
VALUES
('Borys', 'Razin'),
('Olga', 'Proshkina'),
('Ivan', 'Yankovsky');
GO

SELECT * FROM [User];

4. Press Ctrl+Shift+E to execute the Transact-SQL commands.

More info here

How to run MS SQL Server on macOS using Docker.


Pull the SQL Server 2017 Linux container image from Microsoft Container Registry.

sudo docker pull microsoft/mssql-server-linux


Run the container image with Docker

docker run -d --name mssqllinux -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=YourPassword123' -p 1433:1433 microsoft/mssql-server-linux


To view your Docker active containers (container is an instance of the image)

sudo docker ps -a 


-a // active containers

docker container ls


To view your docker images

docker image ls


Remove image

docker rmi -f <image_id>

-f // force


Remove container (you should stop the container before)

docker stop <id_or_name>
docker rm <id_or_name>



Start container after reboot

docker start <id_or_name>

========================


Test connection with sql-cli

Install sql-cli (Node.js should be installed)

sudo npm install -g sql-cli

Connect

mssql -u sa -p YourPassword123

after connection test with the command

select @@version


Microsoft SQL Server 2017 (RTM-CU13) (KB4466404) - 14.0.3048.4 (X64) 
Nov 30 2018 12:57:58 
Copyright (C) 2017 Microsoft Corporation
Developer Edition (64-bit) on Linux (Ubuntu 16.04.5 LTS)

========================

Connect to Database:

Login: sa
Password: YourPassword123
Server: localhost


7 Sept 2019

Getting started React JS. How to deploy React App to Heroku Host.

React JS Start

sudo npm install -g create-react-app

cd react-projects-folder
create-react-app my-app-name

cd my-app-name
npm start

How to deploy React App to Heroku Host.

git init
heroku create $APP_NAME --buildpack mars/create-react-app

// where the $APP_NAME could be like "poshta-app", then it will be used for the domain name: https://poshta-app.herokuapp.com/ 

git add .
git commit -m "Start with create-react-app"
git push heroku master
heroku open

5 Sept 2019

Using Visual Studio Code for AVR (macOS)

Setup IntelliSense

1. Open a project's folder as Workspace in VS Code.
2. Install C/C++ Extension
3. Create a folder .vscode in the project's folder.
4. Place a file c_cpp_properties.json in the .vscode folder

Check documentation here or try the example project.

{
"configurations": [
{
"name": "Mac",
"includePath": [
"/usr/local/include",
"/usr/bin/gcc",
"/Users/usernamefolder/Library/avr-toolchain/avr/include",
"${workspaceRoot}"
],
"defines": [],
"intelliSenseMode": "${default}",
"browse": {
"path": [
"/usr/local/include",
"/usr/bin/gcc",
"/Users/usernamefolder/Library/avr-toolchain/avr/include",
"${workspaceRoot}"
]
},
"compilerPath": "/usr/bin/gcc",
"cStandard": "${default}",
"cppStandard": "${default}"
}
],
"version": 4
}

1 Sept 2019

Make Utility for AVR. (AVR build automation)

The Make Utility is a build tool that automatically determines which source files of a program need to be recompiled and/or linked. We can compile, link and flashing of AVR microcontroller using only one command in the terminal: make. Make remains widely used, especially in Unix-like operating systems.

How to use

1. Create a file inside of project's folder without extension and called Makefile.
2. Place commands in it.
3. Open a terminal and move into the project's folder with Makefile.
4. Type make command in terminal.
5. Use labels like: 
make all
make flash
make clean

Check here the example for ATTiny13

=====

MCU=attiny13
F_CPU=1200000
CC=avr-gcc
CS=avr-size
OBJCOPY=avr-objcopy
CFLAGS=-std=c99 -Wall -g -Os -mmcu=${MCU} -DF_CPU=${F_CPU} -I.
TARGET=main
SRCS=main.c

all:
@printf "\n"
@printf " ===> Compiling: \n"
${CC} ${CFLAGS} -o ${TARGET}.bin ${SRCS}
@printf "\n"
@printf " ===> Size: \n"
${CS} -C ${TARGET}.bin
@printf " ===> Generating .HEX: \n"
${OBJCOPY} -j .text -j .data -O ihex ${TARGET}.bin ${TARGET}.hex

flash:
@printf "\n"
@printf " ===> Flashing: \n"
avrdude -p ${MCU} -B 4 -c usbasp -U flash:w:${TARGET}.hex:i -F -P usb

clean:
@printf "\n"
@printf " ===> Cleaning: \n"
rm -f *.bin *.hex


Popular Posts