• Stars
    star
    152
  • Rank 244,685 (Top 5 %)
  • Language
    C#
  • License
    MIT License
  • Created over 4 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Example of a Blazor WebAssembly project that uses Entity Framework Core on the server for data access.

BlazorWasmEFCoreExample

Image of data grid

Example of a Blazor WebAssembly project that uses Entity Framework Core on the server for data access.

Do you prefer Blazor Server instead? No problem! The same project is implemented for server here.

I created this series of blog posts to explain the project in detail (note: series is valid up to commit e6ac27b):

For the latest version, read about the latest round of refactoring here:

Thank you

๐Ÿ™ Thanks to John Barrett for helping identify initial issues.

Features

  • Application hosted authentication and registration
  • Extended identity features to audit user creation, modification, email confirmation, and deletion
  • Entity Framework Core
  • Multiple data contexts
  • Entity Framework Core logging
  • Shadow properties: the database tracks row version, the user who created the entity and timestamp, and the user who last modified the entity and timestamp, without having to define these properties on the C# domain class
  • Automatic audit that tracks changes with a before/after snapshot and is generated at the data context level
  • Optimistic concurrency with delta resolution (when the database changes, the UI shows the changes so the user can overwrite or abort)
  • Entity validation on the client and server using data annotations
  • A grid that features paging, sorting, and filtering with debounce (i.e. typing three characters will result in just one database round trip)
  • Dynamic filtering and sorting with serverside evaluation
  • 99% of the UI is contained in a Razor class library that is usable from both Blazor WebAssembly and Blazor Server applications
  • Example of the repository pattern: the client and server use the same interface with a different implementation
  • Use of IHttpClientFactory to create a custom client with an authorization message handler

Quick start

Prerequisites

  • .NET Core SDK (3.1.300 or later)
  • Visual Studio Code, OR
  • Visual Studio 2019 16.6 or later

Code and Connection Strings

  1. Optionally fork the repository.

  2. Clone the repository (or your fork):

    git clone https://github.com/jeremylikness/BlazorWasmEFCoreExample.git

  3. If you don't have localdb installed, update appsettings.json and appsettings.Development.json in the ContactsApp.Server project to point to a valid database instance.

  4. The DefaultConnection is used for identity and can have any database name.

  5. The blazorcontactsdb is used for the application database and must match ContactContext.BlazorContactsDb in the ContactsApp.DataAccess project (the default value is blazorcontactsdb).

Visual Studio

  1. Open the solution file.

  2. Ensure the ContactsApp.Server project is set as the start up project.

  3. Open the NuGet Package Manager -> Package Manager Console.

  4. In the console, with the server project selected, create the identity migration by typing:

    Add-Migration -Context ApplicationAuditDbContext Initial

  5. After it is complete, apply the migration:

    Update-Database -Context ApplicationAuditDbContext

  6. You are ready to launch the application.

See note at the end of the next section.

Visual Studio Code

  1. Navigate to the ContactsApp/Server folder.

  2. If you haven't installed the EF Core Command Line Interface (CLI), install it by following these instructions. Choose the latest stable version (the project file currently ships with version 3.1.4).

  3. Run

    dotnet ef migrations add --context ApplicationAuditDbContext Initial

    to set up the identity database migrations.

  4. Run

    dotnet ef database update --context ApplicationAuditDbContext

    to create the identity database.

  5. Type

    dotnet run

    to start the server. Navigate to the port specified.

Note: the demo app is designed to create and populate the contacts database the first time you open the web page. This may result in a delay of up to several minutes on first load. This is normal and is just used to make setup easier. Subsequent runs should load faster.

Migrations for Contacts Database

The context for contacts (ContactContext) resides in the ContactsApp.DataAccess assembly. It is a .NET Standard class library and cannot be executed directly. I created a ContactContextFactory in the ContactsApp.Server project to enable migrations by using the SQL Server provider and loading the connection string. To create a migration, you must specify the executable startup project and the context name. This command will create a migration in the Migrations folder named InitialContact (assuming this is run from the root of the solution directory):

dotnet ef migrations add --startup-project ContactsApp/Server --context ContactContext InitialContact

Use the --namespace parameter to specify a different namespace to help avoid conflicts with the identity context.


Submit any feedback, questions, suggestions, or issues here.

Regards,

Jeremy Likness

@JeremyLikness

More Repositories

1

vanillajs-deck

A Vanilla.js Single Page App (SPA) slide deck for a presentation about Vanilla.js written with no frameworks.
JavaScript
190
star
2

serverless-url-shortener

Azure Function for a URL shortening website. Uses serverless functions, Azure Table Storage and Application Insights.
C#
120
star
3

BlazorState

Examples of how to manage state in Blazor WebAssembly and Blazor Server apps.
HTML
104
star
4

SqliteWasmHelper

Persistent SQLite in Blazor WebAssembly apps with EF Core 6.0 and your browser's cache.
C#
95
star
5

ExpressionGenerator

Example of creating dynamic LINQ expressions
C#
94
star
6

blazor-wasm

Blazor and WebAssembly examples (part of a Blazor presentation)
JavaScript
80
star
7

ExpressionPowerTools

Power tools for working with IQueryable and Expression trees.
C#
77
star
8

BlazorEFCoreMultitenant

Examples of multitenancy using EF Core and Blazor.
C#
73
star
9

explore-cosmos-db

.NET Core 2.0 project to demonstrate some capabilities of Cosmos DB
C#
71
star
10

DurableDungeon

A game designed to teach and learn serverless durable functions in C#
C#
70
star
11

PlanetaryDocs

A complete Blazor Server app using Azure Cosmos DB with EF Core.
C#
61
star
12

azure-fn-file-process-hol

Tutorial for file processing and importing to SQL leveraging serverless Azure Functions.
C#
46
star
13

jsInject

Simple & easy DI for JavaScript.
JavaScript
45
star
14

PASS-2017

Code samples for the Web API Design workshop at PASS Summit 2017
C#
43
star
15

BlazorHealthApp

Example application ported from Angular 2 to Blazor
HTML
37
star
16

sterling-net-core

This is a port of the Sterling Open Source NoSQL database to .NET Standard 2.0.
C#
35
star
17

BlazorMVVM

Implementation of MVVM pattern in Blazor
HTML
31
star
18

jlik.me

URL Shortener project.
C#
31
star
19

ShortLink

Simple version of link shortener
C#
25
star
20

BlazorOData

Build data-driven apps using LINQ and shared models with Blazor and OData.
C#
23
star
21

Angular2HealthApp

Angular Health App Ported to AngularJS 2.0 (beta)
TypeScript
22
star
22

PlasmaWasmRust

Implementation of plasma effect using WebAssembly compiled from Rust.
Rust
21
star
23

MvpSummitTaskList

Example in MVP summit of using connected services and adding (persisted) SQLite to Blazor Wasm.
HTML
21
star
24

6502emulator

Emulator for the 6502 chipset written with TypeScript and Angular 2
TypeScript
20
star
25

AzureBlazorCosmosWasm

A completely serverless solution to access Cosmos DB from Blazor WebAssembly using EF Core.
C#
19
star
26

BlazorServerEFCoreExample

Example of a Blazor Server App that reuses most of the libraries from the related Blazor WebAssembly App example.
HTML
18
star
27

jeremylikness-blog

Developer for Life Blog
HTML
17
star
28

dotnetconf2021

Demos performed by Jeremy Likness for .NET Conf 2021.
C#
16
star
29

SterlingNoSQL

Sterling NoSQL Object-Oriented Database
C#
16
star
30

usda-microservice

Simple Angular 2, Node.js microservices, and Mongo DB example using Docker compose to get up and running.
TypeScript
16
star
31

ExpressionExplorer

A simple console application to explore and transform expressions using ExpressionVisitor.
C#
16
star
32

QueryEvaluationInterceptor

An example of intercepting IQueryable executions to parse and transform the query.
C#
15
star
33

typescript-for-node

Presentation materials for Connect.Tech 2017. Covers building Node.js apps with TypeScript.
CSS
12
star
34

AdvancedBlazor

An advanced Blazor example demonstrating a Razor class library with embedded JavaScript shared between a Blazor Server and a Blazor WebAssembly project.
HTML
12
star
35

AngularTipsAndTricks

Demonstration app of various Angular Tips and Tricks for DevLink 2014 Talk
JavaScript
12
star
36

jlikness.watch

Simple module to enable counting watches in your AngularJS app.
JavaScript
12
star
37

TypeScript-from-JavaScript

Learn TypeScript through a series of refactorings to existing JavaScript code.
JavaScript
12
star
38

AsyncAwaitExplained

Async/await keywords explained: deck and source demos
C#
12
star
39

redux-adventure

A text adventure written with Redux, Angular 2 and TypeScript.
TypeScript
11
star
40

AngularES6HealthApp

The Angular Health App implemented with ECMAScript 6 and Babel.js
JavaScript
11
star
41

wasm-trees

An example of memory management/passing buffers between WebAssembly and JavaScript
C
10
star
42

Ng2TypeScriptLab

A hands-on lab for building your first AngularJS 2.0 apps with TypeScript.
9
star
43

git-fork-branch-cheatsheet

My cheat sheet for the git/fork/branch workflow
9
star
44

BlazorDebounce

Example of an easy way to debounce input without timers.
HTML
9
star
45

tic-tac-toe-ng2

Tic-Tac-Toe with Computer Opponent written in Angular 2 and TypeScript
TypeScript
9
star
46

ng2ts-workshop

Angular 2 with TypeScript day workshop
TypeScript
9
star
47

PlasmaWasmGo

Implementation of Plasma effect in WebAssembly using Go
JavaScript
8
star
48

Angular2ReduxKendoUIHealthApp

An Angular 2 app using Redux and the Kendo UI Angular 2 controls.
TypeScript
8
star
49

micro-locator

Simple services locator.
TypeScript
8
star
50

build-event-grid

Event Grid publisher and consumer example
C#
8
star
51

intro-to-typescript

Introduction to TypeScript for JavaScript developers
CSS
7
star
52

EFCosmosQuickstart

Mirrors the Azure Cosmos DB quickstart using EF Core 5 and EF Core 6
C#
7
star
53

VanillaJs

An example of using modern JavaScript for framework-free development.
TypeScript
7
star
54

qorlate

Promise correlation for AngularJS
JavaScript
7
star
55

AngularDebuggingAndPerformance

Examples for Angular Debugging and Performance course
JavaScript
6
star
56

SparkMLDocCategorization

Example of automatic categorization using .NET for Spark and ML.NET
C#
6
star
57

StarRepo

A .NET 6.0 ASP.NET Core hosts Blazor WebAssembly app demonstrating client and server GraphQL with HotChocolate.
C#
6
star
58

Event-Grid-Glue

Example Event Grid Application
C#
6
star
59

ng2ts-workshop-v2

Angular and TypeScript workshop initially developed for DevNexus 2017
TypeScript
6
star
60

LearnTypeScript

TypeScript examples
TypeScript
5
star
61

AWSMigration

Migrate from AWS Lambda to Azure Functions
JavaScript
5
star
62

TypeScript2016Prez

Presentation covering thet latest (1.8.x) version of TypeScript with examples and deck.
JavaScript
5
star
63

angular-net

Angular examples using .NET Core.
TypeScript
5
star
64

FoodDatabaseMaui

Food database example
C#
4
star
65

RebuildWinJS

Interactive Windows Store app providing a presentation of what's new with WinJS
HTML
4
star
66

Durable-Registry

A solution for 25 days of serverless to implement a holiday registry using serverless Azure Functions and Durable Functions.
C#
3
star
67

bring-own-app-connect-17

Project example (.NET Core 2.0) for Azure lift and shift talk in Connect() 2017.
C#
3
star
68

WinRTExamples

C#
3
star
69

SomeDb

.NET Conference example EF Core 5.0 app showing simple logging, DebugView, and ToQueryString
C#
3
star
70

TelerikNEXT2015

Deck and Code for TelerikNEXT 2015
CSS
3
star
71

JeremyBookWinJs

A simple example of using WinJS
JavaScript
3
star
72

IQueryableExpressionExamples

Examples for the TDevConf presentation "Inside IQueryable: The Power of .NET Expressions."
C#
3
star
73

Jounce

Jounce, a legacy Silverlight framework based on the MVVM pattern and MEF for dependency injection.
C#
3
star
74

redux6502

6502 Emulator Written in Angular 2 and TypeScript with Redux.
TypeScript
2
star
75

T6502

JavaScript
2
star
76

EFCoreModernDataAccess

EF Core demo application for DEVintersection
C#
2
star
77

jsEventAgg

Lightweight event aggregator (publisher/subscriber) for JavaScript
JavaScript
2
star
78

deepskies

Deep skies navigator BUILD demo.
C#
2
star
79

DurableSearch

Example of using Durable Functions HTTP Task to implement a fan-out/fan-in pattern.
C#
2
star
80

ca-acs

Cloud Academy Azure Container Services Demo Code
JavaScript
2
star
81

awesm-stack

AWESM Stack Deck and Code from Atlanta Code Camp
JavaScript
1
star
82

DotNetDocsBuddy

Your friendly .NET docs assistant.
C#
1
star
83

LearnZoneJs

Learn how to use Zone JS
JavaScript
1
star
84

tsviewmodel

ViewModel implementation in TypeScript using decorators for property change notifications
TypeScript
1
star
85

AngularRoutes

Demonstrates how to use various options for routing in Angular
JavaScript
1
star
86

ZoneJS

Presentation about JavaScript Zones
JavaScript
1
star
87

cdams

CDA Team link shortener
C#
1
star
88

PortableIoC

Portable IOC is a tiny thread-safe Inversion of Control container for Universal Windows Platform apps.
C#
1
star
89

BuildWin8Apps

C#
1
star
90

managing-cloud-data

Demo companion for presentation about managing cloud data
1
star
91

docker-we-rise

Hands-on Docker presentation for the We Rise Women in Technology conference in Atlanta 2017.
HTML
1
star
92

ng2-ts-music-city-code

Angular and TypeScript Development for Music City Code
TypeScript
1
star
93

Ng2TypeScriptPrez

Presentation I gave at the Atlanta .NET User Group about building Angular 2 apps with TypeScript.
JavaScript
1
star
94

Angular2HelloWorld

Simple "Hello, World" app with Angular 2 beta
HTML
1
star