Massive data access for MySQL

Massive is a tiny, single-file, data access wrapper around SQL Server. It makes heavy use of System.Dynamic which means that it’s very flexible. It’s really a wrapper which does not get in your way. No extra assemblies, just as single file which you can drop in your solution.

Since Massive is SQL Server only and I work with MySQL, I’ve forked it to add MySQL support.

You can find the repository over at GitHub. There is also a NuGet package available, named Massive.MySQL which has MySQL.Data as a dependency. This means that you only need to do the following to get a working data access wrapper:

Install-Package Massive.MySQL

This will download Massive.MySQL, add it to your project, and download MySQL.Data (which is the only dependency).

I’m quoting the original readme for usage:

Let’s say we have a table named “Products”. You create a class like this:

public class Products:DynamicModel {
    public Products() : base("northwind") {
        PrimaryKeyField = "ProductID";
    }
}

Now you can query thus:

var table = new Products();
//grab all the products
var products = table.All();
//just grab from category 4. This uses named parameters
var productsFour = table.All(columns: "ProductName as Name", where: "WHERE categoryID=@0",args: 4);

You can also run ad-hoc queries as needed:

var result = tbl.Query("SELECT * FROM Categories");

Of course, Massive also supports updates and inserts:

var table = new Products();
var poopy = new {ProductName = "Chicken Fingers"};
//update Product with ProductID = 12 to have a ProductName of "Chicken Fingers"
table.Update(poopy, 12);
//pretend we have a class like Products but it's called Categories
var table = new Categories();
//do it up - the new ID will be returned from the query
var newID = table.Insert(new {CategoryName = "Buck Fify Stuff", Description = "Things I like"});

For more information, please see the README file.

Thank you Rob for your efforts put into this, it’s a great tool.


  • Nicholas Murray

    Hi Alexn,

    I’m giving Massive a try with MySQL after installing via NuGet but I’m running into the following issue

    Keyword not supported: ‘port’.

    Here’s the offending code

        public class Trucks : DynamicModel    {        public Trucks()            : base(“testCon”)        {            PrimaryKeyField = “Id”;        }    }
    Did you experience any issues with the port in your connection string?

    • admin

      Hi Nicholas!

      Sorry for the late reply.

      I have not had any problem with what you’re describing. However, let me try it out and i’ll get back to you. As soon as i get time i will get Massive.MySql some more love.

      Thanks!

  • Rune Jacobsen

    Will this be kept up to date with newer versions of Massive?

    • Alexander Nyquist

      Hi Rune.

      Probably not, I’m afraid. I have been moving away from Massive to Dapper recently.

  • Murray Nicholas

    Found this out a shortly after my last post – thought I would share…

    It seems the provider name is hardcoded as var _providerName = “System.Data.SqlClient”; when it should be var _providerName = “MySql.Data.MySqlClient”;