PostgreSQL .NET Core Entity Framework Example

While working on planning for a new application I decided to look at PostgreSQL vs. SQL Server Express. What drove my decision is the limitations on database size for SQL Server Express. I wanted to stick with Entity Framework as well and decided to go with PostgreSQL after looking at alternatives. I was very impressed with all the features of PostgreSQL and that the PostgreSQL team has a .NET Core Entity Framework provider.

Typically I create a sample console app when working with technology I have not used before (in this case PostgreSQL) so that I have a working example I can refer too and share.  I posted a full working copy of this console app on my GitHub at this link

The sample project (using .NET Core Entity Framework) will truncate a table in PostgreSQL then load a set of Cryptocurrency symbols and query that data with LINQ. 

Sample Screen Shot:

The project takes the approach of a typical setup of Dependency Injection of the service classes required to load and query the data. 

The GitHub project at this link has the steps on what is required to setup this code and run it. 

.NET Core - Google Authentication and .NET Core Identity

This post is just a collection of a couple of links around using Google Authentication and .NET Core Identity. 

  • Free Code Camp: Step by Step adding Google Auth to .NET Core project.
    • By default the SQL Database to support this will be located on your C:\Users\[username] folder.  Change the connection string in appsettings.json to create the database in SQL Server.
  • Microsoft Documentation: Good overview / walk through about using Google Auth but not enough to get the site to work (need the link above).
  • Google Developer Console: This where you need to get your Auth Key.

I have used the Data Repo pattern in .NET Core but wanted to generate the models similar to .NET. 

  • This stackover flow post is a good reference. 
  • How to scaffold models
  • Scaffold-DbContext "Server=yourserver;Database=yourdatabase;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
  • With table params 
  • Scaffold-DbContext "Server=(localdb)\mssqllocaldb;Database=DatabaseName;Trusted_Connection=True;"
    -Provider Microsoft.EntityFrameworkCore.SqlServer
    -OutputDir Models -Context NorthwndContext
    -Tables Products,Categories,Suppliers -Force



Automatic Crypto  Coin Control  - .NET Core App

If you have staked any crypto currencies you know that you have to (with many projects) run what is called “Coin Control” to place all your coins back in one input to get rewards faster.  I decided to build out a .NET Core Control Control application that includes a class library that will communicate with any wallet that uses Bitcoin type RPC commands.   I am currently using this on a staking wallet for the crypto LINDA Project ($LINDA)

Coin Control Process

The coin control process can be time consuming since you do not know when you will get a reward and you have to continue to check your wallet. Doing this automatically would help get rewards more consistently and without any lags. 

Screen shot of the Coin Control App (CC) (Microsoft Windows Example). In this case the CC app will run every 30 minutes checking for a reward. Once a reward is found the CC process runs to send all the coins to the main staking address in the wallet and unlocks the wallet for staking again. 


  • Wallet Passphrase is encrypted by a feature in the app and cannot be decrypted.
  • Email password is encrypted by a feature in the app and cannot be decrypted.
  • The app will not send coins to any address if it does not exist in the staking wallet.


Configuration is very flexible you setup your RPC Information, your staking address, and (using a feature of the app) encrypt your wallet passphrase to make it secure.

There are security features in the app that only allows the Coin Control sending of transactions to an address that exists in the wallet. If you change the “WalletStakingAddress” to an address that does not exist. The app will show an error and the process is halted.

Logging and Email

The application logs all processes and errors and sends emails once a Coin Control cycle is complete.

Use with Other Staking Wallets

We are testing and using this currently for LINDA. Any wallet that supports the following RPC commands would work with this process.

  • getbalance
  • getnewaddress
  • listunspent
  • listaddressgroupings
  • searchrawtransactions
  • sendtoaddress
  • walletpassphrase
  • walletlock

This process has worked so well that I moved any LINDA Master Nodes to all staking. This way I do not have to monitor any issues with a master node.