Introduction

I’ve been using nHibernate for quite a few years now and have been having plenty of success with it. But sometimes it’s just to much. So today I had a little project I had to do and I decided I would take Massive from Rob Connery a spin.

Install

Well, there is no install. Massive is just a gigantic C# file that you would insert into your project if you were using C#. Of course you can’t do that in VB.Net. For VB.Net you just create a new C# Class Library project and call it Massive, no need to be adventurous here. And then you just add a reference to that.

You can now use nuget to add it to your project or just copy pates the Massive.cs file from github or use git of course to do it for you. Plenty of choices.

Configuration

Configuration of Massive is easy. It just needs a connectionstring.

You set the connectionstring in your app.config of your main library and if you have a testproject don’t forget to copy it there too.

The app.config would look something like this.

XML
1
2
3
4
5
6
7
8
9
10
11
<?xml version="1.0"?>
<configuration>
    <connectionStrings>
      <add name="msplog" 
           connectionString="yourconnectionstring" 
           providerName="System.Data.SqlClient"/>
    </connectionStrings>
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
    </startup>
</configuration>
<?xml version="1.0"?>
<configuration>
    <connectionStrings>
      <add name="msplog" 
           connectionString="yourconnectionstring" 
           providerName="System.Data.SqlClient"/>
    </connectionStrings>
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
    </startup>
</configuration>

I’m sure you know what bits to chance to make that work.

The database

I made one table in my database.

Getting the data

And finally we have arrived at the part we need.

First we need to create a Class that inherits from DynamicModel for our Table. We can do this inline or make it a seperate class.

This is the seperate class.

vb.net
1
2
3
4
5
6
7
8
9
10
11
12
13
Imports Massive
 
Namespace Services.MassiveModel
 
    Public Class MspLog
        Inherits DynamicModel
 
        Public Sub New()
            MyBase.new("MspLog", "tbl_MspLog", "Id")
        End Sub
 
    End Class
End Namespace
Imports Massive

Namespace Services.MassiveModel

    Public Class MspLog
        Inherits DynamicModel

        Public Sub New()
            MyBase.new("MspLog", "tbl_MspLog", "Id")
        End Sub

    End Class
End Namespace

I gave three parameters to the constructor. The first one is the name of the connectionstring I want it to use. If you don’t specify that it will just pack the first one. The second is the name of the table and the third is the name of the primary key field I used.

And then I can just query that.

vb.net
1
2
Dim tbl = New MassiveModel.MspLog
Dim logs = tbl.All(orderBy:="DateLog DESC")
Dim tbl = New MassiveModel.MspLog
Dim logs = tbl.All(orderBy:="DateLog DESC")

AS you can see I returned all objects from the table and ordered them by DateLog in a descending order.

Massive uses dynamic objects to return it’s data so you will need to turn Option Strict Off.

And then I can just show those objects to my users.

vb.net
1
2
3
4
For Each log In logs
  Console.WriteLine(log.UserName)
  Console.WriteLine(log.LogDate.ToString)
Next
For Each log In logs
  Console.WriteLine(log.UserName)
  Console.WriteLine(log.LogDate.ToString)
Next

And that is all there is to it.

Conclusion

Massive is also usable if you use winforms and VB.Net. And Massive is pretty simple to use.