This project is no longer maintained on codeplex. It has been moved to github at

https://github.com/tjscience/SqlData

SQL Data

SQL Data is an ORM for C# to SQL without any of the bloat. If you have used ORMs in the past like Entity Framework or NHibernate, you may have noticed that they are ridiculously huge. The reason is that they have much more, sometimes unnecessary, functionality included. If you are using one of these ORMs and are utilizing all of this functionality, then SQL Data is not a good fit. Sql Data is designed to be extremely light weight. The number one goal of this ORM is to allow the developer to obtain data from a SQL database and use this data in strongly typed classes, and do it fast! To put it simply, SQL Data allows you to get data from a SQL database easily, quickly and efficiently.

Here are some of the features included in SQL Data:
  • Manages SQL connections in an intuitive manner
  • Execute statements directly against the database without returning results
  • Query and return a collection CLR classes
  • Query and return dynamic results
  • Query and return a scalar result
  • Handle CRUD operations through intuitive extension methods on your classes
  • You can do bulk inserts of any IList<> with one line of code!
  • and much more...

Here are some of the things that SQL Data does NOT do:
  • Generate classes based on database schema
  • Handle concurrency
  • Slow you down!

Getting Started

Getting started with SQL Data is super easy. There are a couple of things necessary to use SQL Data:
  1. .NET Framework 4
  2. A connection string to the database that you want to use as your data store
  3. Classes that represent your database tables (Optional - you could query dynamically)

Here is the simplest example of using SQL Data:

using System;
using Sql;

namespace HelloData
{
    class Hello 
    {
        static void Main() 
        {
            // Add your named connection - this only has to be done once
            Data.Store.AddConnection("TestDB", "your connection string");

            // Query some data dynamically - returns an IEnumerable<dynamic>
            var results = Data.Store.QueryDynamic("SELECT * FROM Person");
        }
    }
}

That's all there is to it! Notice how we didn't even have to specify the connection to use in the QueryDynamic call? That is because SQL Data will use the first connection if none is specified.

Here is another simple example with a class and using parameters

namespace HelloData
{
    class Hello 
    {
        static void Main() 
        {
            // Add your named connection - this only has to be done once
            Data.Store.AddConnection("TestDB", "your connection string");

            var name = 'A%';
            
            var results = 
                Data.Store.Query<Person>("SELECT * FROM Person WHERE Name LIKE @Name",
                Parameter.Create("Name", name));
        }
    }

    class Person
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }
}

Head over to the Documentation to dig in deeper.



Last edited Dec 12, 2015 at 8:18 PM by tjscience, version 12