ASP.NET Core SignalR

You need these two NuGet packages:

  1. Microsoft.AspNetCore.SignalR.Server
  2. Microsoft.AspNetCore.WebSockets

 

However, I cannot find the first one on Nuget Package Manager. Finally I download it from web:

https://dotnet.myget.org/feed/aspnetcore-master/package/nuget/Microsoft.AspNetCore.SignalR.Server

and then add a local package source in “Nuget Package Manager” to install it.

Then I follow this guide for a simple demo:

https://radu-matei.github.io/blog/signalr-core/

 
Indepth SignalR:

INSIDE SIGNALR – ADDRESSING CLIENTS, RETURN VALUES, BROKEN CONNECTIONS AND SECURITY
 

 

 

 

Starting a Angular 2 project, with ASP.NET Core in VS2017

Prerequistes:

  1. Visual Studio 2017 (you need to install workloads “ASP.NET and web development” and “.NET Core cross-platform development”(not sure…))
  2. Node.js version 6 or later

Please note that you need Visual Studio 2017 release version. This version of Visual Studio include .NET core version 1.0.0. To verify, you can type the following command in command prompt:

dotnet --version

FIRST, you should install the Microsoft ASP.NET Core SPA (Single Page Application) templates. Type the following command in command prompt:

dotnet new --install Microsoft.AspNetCore.SpaTemplates::*

Then, use the following command, a template project will be created:

dotnet new angular

After that, you can use Visual Studio 2017 to open the .csproj file. The project can be compiled and run immediately without any modification.

EF Core with SQLite in VS2017

This post is about using Entity Framework Core to access SQLite database in Visual Studio 2017. I will demonstrate the Database First approach.

 

FIRST, Install the following Nuget packages in your project:

  1. “Microsoft.EntityFrameworkCore.SQLite” (SQLite provider)
  2. “Microsoft.EntityFrameworkCore.Tools” (including”Scaffold-DbContext” and other db commands)
  3. “Microsoft.EntityFrameworkCore.Sqlite.Design” (the “Scaffold-DbContext” need this to generate class for SQLite database)

 

SECOND, Open “Nuget Package Manager Console”. Type the following command

<pre>

Scaffold-DbContext "Datasource=C:\ASPNET\APIApp\webbookmarks.db3" Microsoft.EntityFrameworkCore.SQLite -OutputDir Models

</pre>

After that you should find a XXXContext.cs and other class files representing your data model in the project folder.

 

THIRD, Then add these class files to your project using “Add Existing Items…” in your project menu.

Please note that your database connection string input in the Scaffold-DbContext command will be hard-coded in the datacontext.cs file as follows:

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings.
optionsBuilder.UseSqlite(@"Datasource=C:\Users\bliss\Desktop\bible web\biblebliss\bible.db");
}

 

Finally, you can use use the following code to access the SQLite database:


var = new dbcontext();

var versionshortnames = db.Version.Select(v => v.VersionShort).AsEnumerable();

 

References:

https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.SQLite/
https://docs.microsoft.com/en-us/ef/core/providers/sqlite/