Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Building OpenPOS: Part 7 – NoSQL, MSSQL, SQL CE?

0.00/5 (No votes)
6 May 2010 1  
Building OpenPOS: Part 7 – NoSQL, MSSQL, SQL CE?

One of the BIG overarching goals of OpenPOS is simplicity! You should be able to install OpenPOS using something like click-once and it should just work.

Simplicity? What’s wrong with Microsoft SQL Server Express, it’s simple?

If you are a developer, you would most probably have MSSQL installed, don't you? Well, my target audience might not? This makes the decision of which database to use slightly more complicated. I want to be able to choose…

By default, OpenPOS should use Microsoft SQL Compact 3.5… but if you need to scale, you can use Microsoft SQL Server 2008 R2! This is actually not as hard as it sounds? Linq-to-Sql supports both MSSQL and SQL CE out of the box by just changing the connection sting!

Never heard of SQL CE?

“Microsoft SQL Server Compact (SQL CE) is a compact relational database produced by Microsoft for applications that run on mobile devices and desktops. Prior to the introduction of the desktop platform, it was known as SQL Server for Windows CE and SQL Server Mobile Edition. The latest release is the SQL Server Compact 3.5 SP2 supporting .NET Framework 3.5 as well as Windows Mobile 2003, 5.0, 6.0, and 6.5. It includes both 32-bit and 64-bit native support. SQL CE targets occasionally-connected applications and applications with an embedded database. It is free to download as well as redistribute.”

By using SQL CE, I have NO dependency on any external software… It’s all in-process.

So, how does this work?

I “borrowed” Rob Conery’s ISession implementation

“It's all built around the notion of UnitOfWork and a "Session". If you like NHibernate - you'll feel good here. If you're a Linq to SQL fan, the Data Context is a Unit of Work. The idea is you work on some objects, the Session tracks the changes, then you commit at once. “

public interface ISession : IDisposable
{
    void CommitChanges();
    void Delete<T>(Expression<Func<T, bool>> expression) where T : class;
    void Delete<T>(T item) where T : class;
    void DeleteAll<T>() where T : class;
    T Single<T>(Expression<Func<T, bool>> expression) where T : class;
    System.Linq.IQueryable<T> All<T>() where T : class;
    void Add<T>(T item) where T : class;
    void Add<T>(IEnumerable<T> items) where T : class;
    void Update<T>(T item) where T : class;
}

And now I can use the  LinqToSqlSession:

// dataContext is a "normal" Linq-to-Sql DataContext
LinqToSqlSession session = new LinqToSqlSession(dataContext);

To use SQL CE:

string connectionString = "Data Source=OpenPOS.sdf";

And “Normal” MSSQL:

string connectionString = _
    "Data Source=.\\SQLEXPRESS;Initial Catalog=OpenPOS;Integrated Security=True;";

Nice and easy to use…

What about this new NoSQL “movement”?

The BIG advantage of “borrowing” Rob’s ISession is that I get out-of-the-box support for MongoDB… and it works!!!

“MongoDB bridges the gap between key-value stores (which are fast and highly scalable) and traditional RDBMS systems (which provide rich queries and deep functionality).

MongoDB (from "humongous") is a scalable, high-performance, open source, document-oriented database. Written in C++, MongoDB features:”

If you want to learn more about NoSQL:

What is still on my TODO list: Printing, reporting, configuration & deployment are the BIG things still outstanding.

Here is the source.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here