Git Product home page Git Product logo

booksmart's Introduction

booksmart

Personal learning project using .NET Core MVC Web app to manage Books and Authors

2019-08-09 16_03_47-Index - booksmart

Repo: https://github.com/imran-uk/booksmart

following this but suing "Books" entity https://docs.microsoft.com/en-us/aspnet/core/tutorials/razor-pages/?view=aspnetcore-2.2

Using MySQL, decided to use MariaDB which I installed here https://mariadb.org/

just choose msi installer on Windows

i got latest GA on 10.4 series 64-bit arch

mariadb-10.4.7-winx64.msi

commandz n shiz

mkdir /c/code/booksmart
git clone https://github.com/imran-uk/booksmart.git

created gitignore

vim .gitignore
git st
git add .gitignore
git st
git commit -m"add gitignore"

i'm using v2.2

dotnet --version

use webapp template

dotnet new webapp

with Visual Studio code

code .

code should auto-update and restore, you might want to hity ctrl+f5 to build n run dat mofo first

do dis for good measure (maybe)

dotnet restore

create HTTPS certs

dotnet dev-certs https --trust

to make use of the EF magic, we need a few packages

dotnet add package MySql.Data.EntityFrameworkCore
dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design
dotnet add package Microsoft.EntityFrameworkCore.Design

ensure the MySQL connection string is here

cat appsettings.json

install dis tool

dotnet tool install --global dotnet-aspnet-codegenerator

lets use aspnet-codegenerator tool... to auto-generate the scaffolding shiz

dotnet aspnet-codegenerator razorpage -m Book -dc BookSmartBookContext -udl -outDir Pages/Book --referenceScriptLibraries

now lets create the files which contain code to create tables we need

dotnet ef migrations add InitialCreate

...and now create the tables in MySQL

dotnet ef database update

it don't work, wtf? lets verbose dat mofo

dotnet ef -v database update

might be due to MySQL connector not supporting migrations yet, lets manually generate the SQL script

dotnet ef migrations script

at this point i had to copy-pasta the generated SQL and run against the database manually (had to munge it a bit too)

CREATE TABLE `__EFMigrationsHistory` (
    `MigrationId` varchar(150) NOT NULL,
    `ProductVersion` varchar(32) NOT NULL,
    PRIMARY KEY (`MigrationId`)
);

CREATE TABLE `Book` (
    `Id` int NOT NULL AUTO_INCREMENT,
    `Title` text NULL,
    `ReleaseDate` datetime NOT NULL,
    PRIMARY KEY (`Id`)
);

INSERT INTO `__EFMigrationsHistory` (`MigrationId`, `ProductVersion`)
VALUES ('20190809132302_InitialCreate', '2.2.6-servicing-10079');

now start the app, you should be able to do CRUD operations on books

https://localhost:5001/Book


IF EXISTS(SELECT 1 FROM information_schema.tables
  WHERE table_name = '
__EFMigrationsHistory' AND table_schema = DATABASE())
BEGIN
CREATE TABLE `__EFMigrationsHistory` (
    `MigrationId` varchar(150) NOT NULL,
    `ProductVersion` varchar(32) NOT NULL,
    PRIMARY KEY (`MigrationId`)
);

END;

TODO

  • add support for Author

  • wire-up Authors to Books

a book can have 1 or more Authors

an Author can be author of 0 or more Books

  • how to use MySQL client from GitBash and with history and autocomplete of table names

  • create MySQL database non-root user

remember to update settings file

booksmart's People

Contributors

imran-uk avatar

Stargazers

 avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.