nopCommerce with NuoDB – Part 2

In the first installment of this two part series we talked briefly about the benefits of running NuoDB as a database backend for nopCommerce. If you wanted more detail, or just to see it in action, I recommended watching the on-demand webinar “Enabling Scalability & Redundancy in eCommerce.” Today, I’d like to introduce you to some of the details for how nopCommerce was enhanced to run on NuoDB, and to provide a peek under the covers of the “Next-Next-Next” installation.

The port itself is basically a change in the nopCommerce database layer and in the install page (because you need to select a new type of database). Thus, if you’d like to take this port into new versions of nopCommerce it shouldn’t take long.

The easiest way to get started is to download the NuoDB sources from GitHub If you’re eager to try what you have seen in the webinar, I strongly recommend reading the Deploying.Readme.txt file first. Once you build the solution in Visual Studio – and remember, you need to have NuoDB ADO.NET driver (NuoDb.Data.Client.dll) on that system – and have prepared your NuoDB database, you can proceed with the installation.

The installation does not differ from vanilla nopCommerce installation. You don’t need to perform any hacking. Everything is done, as usual, via the web.

Internally, NopCommerce is using Entity Framework - even for the installation. Entity Framework is able to scaffold the model you’re working with and, together with mapping specifications (either explicit or thanks to conventions), create a SQL script with some cooperation with a provider. That’s what the installation is doing as a first step. The script is then executed one statement at a time creating tables, columns, etc. All the main logic is in <a 9fa92f1e0fd300a28797f9a735b9a4cdb6215e1c=”” blob=”””” href=”&lt;a href=” https:=”” initializers=”” libraries=”””” nopcommerce=”” nuodb=”” p=”“> </a>

<a 9fa92f1e0fd300a28797f9a735b9a4cdb6215e1c="" blob="""" href="&lt;a href=" https:="" initializers="" libraries="""" nopcommerce="" nuodb="" p="">
namespace Nop.Data.Initializers
	public class NuoDbDatabaseInitializer : IDatabaseInitializer where TContext : DbContext
		public void InitializeDatabase(TContext context)
			if (context == null)
				throw new ArgumentNullException("context");
			using (var ts = new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions() { Timeout = TimeSpan.FromHours(1) }))
				if (IsInitialized(context))
				var script = ((IObjectContextAdapter)context).ObjectContext.CreateDatabaseScript();
				foreach (var item in script.Split(';').Where(x => !string.IsNullOrWhiteSpace(x)).Select(x => x.Trim()))
				context.Database.ExecuteSqlCommand("create table _nopCommerce_NuoDB (dummy int)");
		static bool IsInitialized(TContext context)
				context.Database.ExecuteSqlCommand("select dummy from _nopCommerce_NuoDB fetch first 0");
				return true;
				return false;
		protected virtual void Seed(TContext context)
		{ }

<a 9fa92f1e0fd300a28797f9a735b9a4cdb6215e1c=”” blob=”””” href=”&lt;a href=” https:=”” initializers=”” libraries=”””” nopcommerce=”” nuodb=”” p=”“> </a>

<a 9fa92f1e0fd300a28797f9a735b9a4cdb6215e1c=”” blob=”””” href=”&lt;a href=” https:=”” initializers=”” libraries=”””” nopcommerce=”” nuodb=”” p=”“>Then – depending on your selection – the sample data is created. This is in fact the standard process of using Entity Framework. The installation creates new instances of entities and saves these into the database. All this “magic” happens thanks to NuoDbDataProvider class that’s plugged into nopCommerce and all the recent improvements in the .NET driver [&lt;/a&gt;&lt;a href=””&gt;Entity Framework support&lt;/a&gt;, &lt;a href=””&gt;Connection Pooling&lt;/a&gt;, &lt;a href=””&gt;.NET&lt;/a&gt;]. The driver was improved a lot and hence the upper layers cannot see really what’s beneath the Entity Framework layer. This might look like obvious or expected behavior – especially for people using it only with Microsoft SQL Server – but that’s the trick really. Believe me, to see it running for the first time, with only few modifications in nopCommerce (and heavy work in the driver), was electric for me.

After you finish your installation (it’s going to take a minute or two, so grab a delicious beverage and relax), you can start configuring nopCommerce and playing with it. You can check the database structure later to see why it took so long, there are some impressive tables.

And that’s it. You not only installed nopCommerce on NuoDB, but you should also now have an understanding of where most of the important NuoDB-ish magic comes from.

Happy e-commercing with NuoDB.

<em>If you have any questions, feel free to leave a comment and I’ll try to answer all.</em>

Add new comment