Friday, August 17, 2018

SOLID Principles in OOP

(S)ingle Responsibility Principle
This states that a class should only have a single responsibility.

(O)pen Closed Principle
Open for extension and closed for modifications.

(L)iskov Substitution Principle
Objects should be replaceable with instances of their subtypes

(I)nterface Segregation Principle
Many client-specific interfaces are better than one general-purpose interface

(D)ependency Inversion Principle
Depend upon abstractions, not concretions



Reference
https://en.wikipedia.org/wiki/SOLID

Entity Framework Core Notes Part 1

We execute command line commands to add/update database or to generate model from a database.
We can either execute them on the command line,  powershell or Visual Studio's package manager console.

On previous versions of Entity Framework, we need to execute the command below to setup migrations on the project, to create the migrations folder:

> enable-migrations 

This is already considered obsolete in Entity Framework Core. The Add-Migrations script automatically creates for you the migrations folder, unless you have specified it explicitly with specific command line parameters.


Commands (Package Manager Console):

Adding migration scripts to the project.

> Add-Migration

Specifying a Migration name

> Add-Migration MyFirstMigration

Specifying a Migrations output directory

> Add-Migration MyOtherMigration -OutputDir OtherMigrationsDirectory

Targeting a Project for Migration

> Add-Migration SpecifiedProjectMigration -Project OtherCodeFirstProject

Applying the Migration scripts to the Database

> Update-Database

The following command removes the previous Migration

> Remove-Migration


Creating your models from an existing database


> Scaffold-DbContext "<ConnectionString>" Microsoft.EntityFramework.SqlServer -OutputDir Models

Thursday, August 9, 2018

Entity Framework Core 2.1 Package Installation

Entity Framework Core Packages
On your project install the following NuGet Packages


  • Microsoft.EntityFrameworkCore
  • Microsoft.EntityFrameworkCore.Design
  • Microsoft.EntityFrameworkCore.Relational
  • Microsoft.EntityFrameworkCore.SqlServer  -- Provider based
  • Microsoft.EntityFrameworkCore.Tools -- (optional)

Installing the packages using Package Manager Console (Tools > NuGet Package Manager > Package Manager Console)
  1. Make sure you are in the correct directory by typing in dir then press enter.
  2. Install-Package <Package Name> 

Installing the packages using Visual Studio's NuGet Package Manager
  1. Go to Tools > NuGet Package Manager > Manage NuGet Packages for Solution
  2. Search for Microsoft.EntityFrameworkCore

Installing the packages by editing the Project (Visual Studio 2017)

Another way of installing the EF packages is by editing the project. Paste in the following inside the <Project> scope.

<ItemGroup>
   <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.3" />
   <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="2.0.3" />
   <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.3" />
   <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.3" />
   <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.3" />
</ItemGroup>

Save project then on the Package Manager Console, enter the command below to restore the packages to the project:

> dotnet restore