Link to CompleteData Project
 https://snappro.azurewebsites.net/Time/Tasks/Details/22649

1) Create Database SnapProduction

2) Apply Database Script located at: C:\Users\chest\OneDrive\Documents\SQL Server Management Studio\SnapProduction.sql
Copy to clipboard, right click dbase, Add new query and paste then execute

3) Update Server project with NuGet Packages

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="3.2.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.3" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.2" />
</ItemGroup>

4) Apply to Server with .NET CLI:

dotnet ef dbcontext scaffold "Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=SnapProduction" Microsoft.EntityFrameworkCore.SqlServer --context-dir Data --output-dir Models
Ref: https://docs.microsoft.com/en-us/ef/core/managing-schemas/scaffolding?tabs=dotnet-core-cli

5) Move Models accordingly and change namespaces

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

/****** Object: Table [dbo].[FileDoc] Script Date: 12/24/2020 11:06:38 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FileDoc](
[DocumentID] [int] IDENTITY(1,1) NOT NULL,
[CreatedByUser] [nvarchar](80) NULL,
[DateAdded] [datetime] NOT NULL,
[Description] [nvarchar](1000) NOT NULL,
[FolderID] [int] NULL,
[Path] [nvarchar](200) NULL,
[Thumbnail] [nvarchar](200) NULL,
CONSTRAINT [PK_dbo.FileDoc] PRIMARY KEY CLUSTERED
(
[DocumentID] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[Folder] Script Date: 12/24/2020 11:06:38 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Folder](
[FolderID] [int] IDENTITY(1,1) NOT NULL,
[Active] [bit] NOT NULL,
[CreatedBy] [nvarchar](80) NULL,
[DateAdded] [datetime] NOT NULL,
[Description] [nvarchar](200) NOT NULL,
[FolderName] [nvarchar](100) NOT NULL,
[IsPrivate] [bit] NOT NULL,
[ParentFolderID] [int] NULL,
[IsPublic] [bit] NOT NULL,
[IsRestricted] [bit] NOT NULL,
[IsPersonal] [bit] NOT NULL,
CONSTRAINT [PK_dbo.Folder] PRIMARY KEY CLUSTERED
(
[FolderID] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Folder] ADD DEFAULT ((0)) FOR [IsPublic]
GO
ALTER TABLE [dbo].[Folder] ADD DEFAULT ((0)) FOR [IsRestricted]
GO
ALTER TABLE [dbo].[Folder] ADD DEFAULT ((0)) FOR [IsPersonal]
GO
ALTER TABLE [dbo].[FileDoc] WITH CHECK ADD CONSTRAINT [FK_dbo.FileDoc_dbo.Folder_FolderID] FOREIGN KEY([FolderID])
REFERENCES [dbo].[Folder] ([FolderID])
GO
ALTER TABLE [dbo].[FileDoc] CHECK CONSTRAINT [FK_dbo.FileDoc_dbo.Folder_FolderID]
GO

Author: Chester Bryndza

  • Author image
    Published: Thursday, December 24, 2020
    Scope: Restricted
    Tag: BLAZOR