Quick Start Using Massive and PostGreSQL

Most of the documentation for using Massive is OK – there are one or two things you might need to be aware of when you start a project from scratch – and I mean from scratch.  Follow these steps and you shouldn’t go far wrong.

Database

OK – so I have a PostgreSQL database installed (called “geodb”) and I have table called Report.

report table

As you can see it’s just some basic text and ids, nothing special here.

I create a new Windows application using Visual Studio, it could be a console app – it’s not important – just something to get you started.

Install Npgsql

You will need to have the Npgsql installed/referenced into your project, so you can at least “talk” to the database, and Massive needs this to be able to do this.  In the Package Manager Console just type (bear in mind the version will probably be different when you read this):

PM> Install-Package Npgsql -Version 3.0.4

npgsql

Modify App.config

This is always mentioned – but you do have to modify you App.config for you project.  This is so Massive can find your database connection string and it knows which dll to load in to talk to the database – which is the Npgsql.dll in this case.

proj_appconfig

Your App.Config should look like this:

appconfig

The connection string goodness and DbProviderFactories section detailing the dll – make sure the Version tallies up with the one in your project – just get the properties of the dll from the References treeview in the project.

version

Create Massive Class

Quite easy to do – you can add Massive by Nuget, or just copy paste the code from GitHub for the PostgreSQL version and make a new class file.

Create Report Class

Create a new class – inheriting DynamicModel, passing in the name of database, the table and the primary key.


public class Report: DynamicModel
{
    public Report() : base("geodb", "report", "id")
    {
    }
}

 

Test Code

Make an instance of the class by copying the code below:

var table = new Report();
foreach (var rec in table.All())
{
     / /These apply to the column names.
     Console.WriteLine("{0} {1} ", rec.id, rec.name);
}

 

Put the code in a Main() method or button click event to just test the code and it should just all work fairy easily.

Quick Start Using Massive and PostGreSQL