Skip to content

Instantly share code, notes, and snippets.

@atiq-cs
Created July 6, 2018 19:50
Show Gist options
  • Save atiq-cs/2cfe23a43a296685aaea1fc379ce3ac0 to your computer and use it in GitHub Desktop.
Save atiq-cs/2cfe23a43a296685aaea1fc379ce3ac0 to your computer and use it in GitHub Desktop.
MVC with EF SQL DB hello world demo
$ dotnet ef -v migrations add InitialCreate
Using project 'D:\git_ws\net-core-demos\P2_MVC_SQLDB\P2_MVC_SQLDB.csproj'.
Using startup project 'D:\git_ws\net-core-demos\P2_MVC_SQLDB\P2_MVC_SQLDB.csproj'.
Writing 'D:\git_ws\net-core-demos\P2_MVC_SQLDB\obj\P2_MVC_SQLDB.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\atiqc\AppData\Local\Temp\tmp8E9B.tmp /verbosity:quiet /nologo D:\git_ws\net-core-demos\P2_MVC_SQLDB\P2_MVC_SQLDB.csproj
Writing 'D:\git_ws\net-core-demos\P2_MVC_SQLDB\obj\P2_MVC_SQLDB.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\atiqc\AppData\Local\Temp\tmp90FD.tmp /verbosity:quiet /nologo D:\git_ws\net-core-demos\P2_MVC_SQLDB\P2_MVC_SQLDB.csproj
dotnet build D:\git_ws\net-core-demos\P2_MVC_SQLDB\P2_MVC_SQLDB.csproj /verbosity:quiet /nologo
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:04.72
dotnet exec --depsfile D:\git_ws\net-core-demos\P2_MVC_SQLDB\bin\Debug\netcoreapp2.1\P2_MVC_SQLDB.deps.json --additionalprobingpath C:\Users\atiqc\.nuget\packages --additionalprobingpath "C:\Program Files\dotnet\sdk\NuGetFallbackFolder" --runtimeconfig D:\git_ws\net-core-demos\P2_MVC_SQLDB\bin\Debug\netcoreapp2.1\P2_MVC_SQLDB.runtimeconfig.json "C:\Program Files\dotnet\sdk\2.1.300\DotnetTools\dotnet-ef\2.1.0\tools\netcoreapp2.1\any\tools\netcoreapp2.0\any\ef.dll" migrations add InitialCreate --assembly D:\git_ws\net-core-demos\P2_MVC_SQLDB\bin\Debug\netcoreapp2.1\P2_MVC_SQLDB.dll --startup-assembly D:\git_ws\net-core-demos\P2_MVC_SQLDB\bin\Debug\netcoreapp2.1\P2_MVC_SQLDB.dll --project-dir D:\git_ws\net-core-demos\P2_MVC_SQLDB\ --language C# --working-dir D:\git_ws\net-core-demos\P2_MVC_SQLDB --verbose --root-namespace P2_MVC_SQLDB
Using assembly 'P2_MVC_SQLDB'.
Using startup assembly 'P2_MVC_SQLDB'.
Using application base 'D:\git_ws\net-core-demos\P2_MVC_SQLDB\bin\Debug\netcoreapp2.1'.
Using working directory 'D:\git_ws\net-core-demos\P2_MVC_SQLDB'.
Using root namespace 'P2_MVC_SQLDB'.
Using project directory 'D:\git_ws\net-core-demos\P2_MVC_SQLDB\'.
Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Finding application service provider...
Finding IWebHost accessor...
Using environment 'Development'.
Using application service provider from IWebHost accessor on 'Program'.
Found DbContext 'BloggingContext'.
Finding DbContext classes in the project...
Using context 'BloggingContext'.
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
Entity Framework Core 2.1.0-rtm-30799 initialized 'BloggingContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer' with options: None
Finding design-time services for provider 'Microsoft.EntityFrameworkCore.SqlServer'...
Using design-time services from provider 'Microsoft.EntityFrameworkCore.SqlServer'.
Finding design-time services referenced by assembly 'P2_MVC_SQLDB'.
No referenced design-time services were found.
Finding IDesignTimeServices implementations in assembly 'P2_MVC_SQLDB'...
No design-time services were found.
Writing migration to 'D:\git_ws\net-core-demos\P2_MVC_SQLDB\Migrations\20180706192240_InitialCreate.cs'.
Writing model snapshot to 'D:\git_ws\net-core-demos\P2_MVC_SQLDB\Migrations\BloggingContextModelSnapshot.cs'.
Done. To undo this action, use 'ef migrations remove'
$ dotnet ef -v database update
Using project 'D:\Code\netcore\P02_MVC\P02_MVC.csproj'.
Using startup project 'D:\Code\netcore\P02_MVC\P02_MVC.csproj'.
Writing 'D:\Code\netcore\P02_MVC\obj\P02_MVC.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\atiqc\AppData\Local\Temp\tmp5CA2.tmp /verbosity:quiet /nologo D:\Code\netcore\P02_MVC\P02_MVC.csproj
Writing 'D:\Code\netcore\P02_MVC\obj\P02_MVC.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\atiqc\AppData\Local\Temp\tmp5F04.tmp /verbosity:quiet /nologo D:\Code\netcore\P02_MVC\P02_MVC.csproj
dotnet build D:\Code\netcore\P02_MVC\P02_MVC.csproj /verbosity:quiet /nologo
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:00.89
dotnet exec --depsfile D:\Code\netcore\P02_MVC\bin\Debug\netcoreapp2.1\P02_MVC.deps.json --additionalprobingpath C:\Users\atiqc\.nuget\packages --additionalprobingpath "C:\Program Files\dotnet\sdk\NuGetFallbackFolder" --runtimeconfig D:\Code\netcore\P02_MVC\bin\Debug\netcoreapp2.1\P02_MVC.runtimeconfig.json "C:\Program Files\dotnet\sdk\2.1.300\DotnetTools\dotnet-ef\2.1.0\tools\netcoreapp2.1\any\tools\netcoreapp2.0\any\ef.dll" database update --assembly D:\Code\netcore\P02_MVC\bin\Debug\netcoreapp2.1\P02_MVC.dll --startup-assembly D:\Code\netcore\P02_MVC\bin\Debug\netcoreapp2.1\P02_MVC.dll --project-dir D:\Code\netcore\P02_MVC\ --language C# --working-dir D:\Code\netcore\P02_MVC --verbose --root-namespace P02_MVC
Using assembly 'P02_MVC'.
Using startup assembly 'P02_MVC'.
Using application base 'D:\Code\netcore\P02_MVC\bin\Debug\netcoreapp2.1'.
Using working directory 'D:\Code\netcore\P02_MVC'.
Using root namespace 'P02_MVC'.
Using project directory 'D:\Code\netcore\P02_MVC\'.
Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Finding application service provider...
Finding IWebHost accessor...
Using environment 'Development'.
Using application service provider from IWebHost accessor on 'Program'.
Found DbContext 'BloggingContext'.
Finding DbContext classes in the project...
Using context 'BloggingContext'.
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
Entity Framework Core 2.1.0-rtm-30799 initialized 'BloggingContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer' with options: None
Finding design-time services for provider 'Microsoft.EntityFrameworkCore.SqlServer'...
Using design-time services from provider 'Microsoft.EntityFrameworkCore.SqlServer'.
Finding design-time services referenced by assembly 'P02_MVC'.
No referenced design-time services were found.
Finding IDesignTimeServices implementations in assembly 'P02_MVC'...
No design-time services were found.
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (265ms) [Parameters=[], CommandType='Text', CommandTimeout='60']
CREATE DATABASE [EFGetStarted.AspNetCore.NewDb];
Executed DbCommand (265ms) [Parameters=[], CommandType='Text', CommandTimeout='60']
CREATE DATABASE [EFGetStarted.AspNetCore.NewDb];
infoExecuted DbCommand (49ms) [Parameters=[], CommandType='Text', CommandTimeout='60']
IF SERVERPROPERTY('EngineEdition') <> 5
BEGIN
ALTER DATABASE [EFGetStarted.AspNetCore.NewDb] SET READ_COMMITTED_SNAPSHOT ON;
END;: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (49ms) [Parameters=[], CommandType='Text', CommandTimeout='60']
IF SERVERPROPERTY('EngineEdition') <> 5
BEGIN
ALTER DATABASE [EFGetStarted.AspNetCore.NewDb] SET READ_COMMITTED_SNAPSHOT ON;
END;
Executed DbCommand (7ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE TABLE [__EFMigrationsHistory] (
[MigrationId] nvarchar(150) NOT NULL,
[ProductVersion] nvarchar(32) NOT NULL,
CONSTRAINT [PK___EFMigrationsHistory] PRIMARY KEY ([MigrationId])
);info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (7ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE TABLE [__EFMigrationsHistory] (
[MigrationId] nvarchar(150) NOT NULL,
[ProductVersion] nvarchar(32) NOT NULL,
CONSTRAINT [PK___EFMigrationsHistory] PRIMARY KEY ([MigrationId])
);
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (4ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT OBJECT_ID(N'[__EFMigrationsHistory]');
Executed DbCommand (4ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT OBJECT_ID(N'[__EFMigrationsHistory]');
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT [MigrationId], [ProductVersion]
FROM [__EFMigrationsHistory]
ORDER BY [MigrationId];
Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT [MigrationId], [ProductVersion]
FROM [__EFMigrationsHistory]
ORDER BY [MigrationId];
Applying migration '20180702043401_InitialCreate'.
info: Microsoft.EntityFrameworkCore.Migrations[20402]
Applying migration '20180702043401_InitialCreate'.
infoExecuted DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE TABLE [Blogs] (
[BlogId] int NOT NULL IDENTITY,
[Url] nvarchar(max) NULL,
CONSTRAINT [PK_Blogs] PRIMARY KEY ([BlogId])
);: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE TABLE [Blogs] (
[BlogId] int NOT NULL IDENTITY,
[Url] nvarchar(max) NULL,
CONSTRAINT [PK_Blogs] PRIMARY KEY ([BlogId])
);
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE TABLE [Posts] (
[PostId] int NOT NULL IDENTITY,
[Title] nvarchar(max) NULL,
[Content] nvarchar(max) NULL,
[BlogId] int NOT NULL,
CONSTRAINT [PK_Posts] PRIMARY KEY ([PostId]),
CONSTRAINT [FK_Posts_Blogs_BlogId] FOREIGN KEY ([BlogId]) REFERENCES [Blogs] ([BlogId]) ON DELETE CASCADE
);
Executed DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE TABLE [Posts] (
[PostId] int NOT NULL IDENTITY,
[Title] nvarchar(max) NULL,
[Content] nvarchar(max) NULL,
[BlogId] int NOT NULL,
CONSTRAINT [PK_Posts] PRIMARY KEY ([PostId]),
CONSTRAINT [FK_Posts_Blogs_BlogId] FOREIGN KEY ([BlogId]) REFERENCES [Blogs] ([BlogId]) ON DELETE CASCADE
);
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE INDEX [IX_Posts_BlogId] ON [Posts] ([BlogId]);
Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE INDEX [IX_Posts_BlogId] ON [Posts] ([BlogId]);
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20180702043401_InitialCreate', N'2.1.0-rtm-30799');
Executed DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20180702043401_InitialCreate', N'2.1.0-rtm-30799');
Done.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment