Fast, lightweight .NET micro-ORM
C# Other
Latest commit 35e236f Dec 1, 2016 @Jaxelr Jaxelr committed on GitHub Update README.md
Update Readme to use code blocks by language.
Permalink
Failed to load latest commit information.
.nuget Added NUnit.Runners package Jun 13, 2014
Build Added code snippets for Repository generation Jun 21, 2012
Insight.Database.Compatibility3x Fixed issue with Compatibility3x Feb 11, 2015
Insight.Database.Configuration Updated library dependencies Jun 11, 2014
Insight.Database.Json StyleCop fixes Aug 24, 2015
Insight.Database.Providers.DB2 Rebuilt mapping configuration system and allowed for mapping into child Sep 25, 2014
Insight.Database.Providers.Default Fixed code analysis issues Mar 5, 2015
Insight.Database.Providers.Glimpse Fixed Issue #158 - bulkcopy fails when connection is wrapped with Gli… Nov 8, 2014
Insight.Database.Providers.MiniProfiler Removed call to System.Activator in wrapped connections Jul 1, 2014
Insight.Database.Providers.MySql Fixed case of MySql folder Mar 5, 2015
Insight.Database.Providers.Oracle Fixed code analysis issues Mar 5, 2015
Insight.Database.Providers.OracleManaged FIXED Issue #205 - updated to official Oracle Managed Provider Aug 23, 2015
Insight.Database.Providers.PostgreSQL Implemented Issue #194 - JSON/b data types in PostgreSQL Mar 16, 2015
Insight.Database.Providers.Sample Moved default providers into their own assembly Mar 24, 2014
Insight.Database.Providers.Sybase Moved default providers into their own assembly Mar 24, 2014
Insight.Database.Providers.SybaseAse Rebuilt mapping configuration system and allowed for mapping into child Sep 25, 2014
Insight.Database.Sample Rebuilt mapping configuration system and allowed for mapping into child Sep 25, 2014
Insight.Database Fixes NET40 build where DBConnectionExtensions was using a DBASYNC call Sep 6, 2016
Insight.Tests.Compatibility3x Tests.Oracle needed Copy Local = true on the Oracle.DataAccess dll. A… Aug 29, 2016
Insight.Tests.DB2 Added vagrant boxes for test database servers Mar 9, 2015
Insight.Tests.Glimpse Tests.Oracle needed Copy Local = true on the Oracle.DataAccess dll. A… Aug 29, 2016
Insight.Tests.Json Tests.Oracle needed Copy Local = true on the Oracle.DataAccess dll. A… Aug 29, 2016
Insight.Tests.MiniProfiler Tests.Oracle needed Copy Local = true on the Oracle.DataAccess dll. A… Aug 29, 2016
Insight.Tests.MySql Added vagrant boxes for test database servers Mar 9, 2015
Insight.Tests.Oracle Tests.Oracle needed Copy Local = true on the Oracle.DataAccess dll. A… Aug 29, 2016
Insight.Tests.OracleManaged FIXED Issue #205 - updated to official Oracle Managed Provider Aug 23, 2015
Insight.Tests.PostgreSQL Added test case for Issue #207 Aug 24, 2015
Insight.Tests.SQLite Updated library dependencies Jun 11, 2014
Insight.Tests.SybaseAse Added vagrant boxes for test database servers Mar 9, 2015
Insight.Tests Tests.Oracle needed Copy Local = true on the Oracle.DataAccess dll. A… Aug 29, 2016
Vagrant The PostgreSQL vagrant setup must be updated for the new point releas… Aug 29, 2016
packages Pulled System.Configuration classes out into another assembly Mar 24, 2014
.editorconfig Added editorconfig file Jan 15, 2013
.gitattributes Added vagrant boxes for test database servers Mar 9, 2015
.gitignore Added .vagrant to gitignore Mar 5, 2015
Build.bat Updated build process Mar 27, 2013
Build.ps1 Expanded build notes Aug 28, 2016
Build.psake.ps1 Fixes quotes when building project from powershell Sep 6, 2016
Building.txt Adds direct links to database drivers in building.txt Sep 6, 2016
Insight.Database.pub Moved default providers into their own assembly Mar 24, 2014
Insight.Database.snk Added strong names signing Jan 1, 2014
Insight.sln Added vagrant boxes for test database servers Mar 9, 2015
InsightDatabase.png Added project icon Nov 25, 2013
License.txt Updated License.txt Jul 8, 2013
README.md Update README.md Dec 1, 2016
Settings.StyleCop Cleaned up code Jun 18, 2013
Vagrantfile Added vagrant configuration for Hyper-V Sep 9, 2016

README.md

Insight.Database

Insight.Database is a fast, lightweight, (and dare we say awesome) micro-orm for .NET. It's available as a NuGet Package.

Whoops. Forgot to mention easy. It's easy too. And you can also take control of pieces if you want to.

Let's say you have a database and a class and you want them to work together. Something like this:

CREATE TABLE Beer ([ID] [int], [Type] varchar(128), [Description] varchar(128)) GO
CREATE PROC InsertBeer @type varchar(128), @description varchar(128) AS
    INSERT INTO Beer (Type, Description) OUTPUT inserted.ID
        VALUES (@type, @description) GO
CREATE PROC GetBeerByType @type [varchar] AS SELECT * FROM Beer WHERE Type = @type GO
public class Beer
{
    public int ID { get; private set; }
    public string Type { get; set; }
    public string Description { get; set; }
}

    var beer = new Beer() { Type = "ipa", Description = "Sly Fox 113" };

Let's get Insight.Database:

PM> Install-Package Insight.Database

Tell it what database you're using:

SqlInsightDbProvider.RegisterProvider(); // or Oracle, DB2, Postgres, MySql...

Now, wire up those stored procedures to an interface with a single connection.As<T>:

public interface IBeerRepository
{
    void InsertBeer(Beer beer);
    IList<Beer> GetBeerByType(string type);
    void UpdateBeerList(IList<Beer> beerList);
}

var repo = connection.As<IBeerRepository>();

repo.InsertBeer(beer);
IList<Beer> beerList = repo.GetBeerByType("ipa");
repo.UpdateBeerList(beerList);

Look, ma! No mapping code! (Plus, you can now inject that interface with a DI framework or mock the interface for testing.)

Want to work at a lower level? Let's call a stored proc with an anonymous object. (It also automatically opens and closes the connection.)

// auto open/close
conn.Execute("AddBeer", new { Name = "IPA", Flavor = "Bitter"});

Objects are mapped automatically. No config files, no attributes. Just pure, clean magic:

// auto object mapping
Beer beer = new Beer();
conn.Execute("InsertBeer", beer);
List<Beer> beers = conn.Query<Beer>("FindBeer", new { Name = "IPA" });

Yes, even nested objects. Insight will just figure it out for you:

// auto object graphs
var servings = conn.Query<Serving, Beer, Glass>("GetServings");
foreach (var serving in servings)
    Console.WriteLine("{0} {1}", serving.Beer.Name, serving.Glass.Ounces);

Feel free to return multiple result sets. We can handle them:

// multiple result sets
var results = conn.QueryResults<Beer, Chip>("GetBeerAndChips", new { Pub = "Fergie's" }));
IList<Beer> beer = results.Set1;
IList<Chip> chips = results.Set2;

Or perhaps you want to return multiple independent recordsets, with one-to-many and one-to-one relationships. It's not possible! Or is it?

var results = conn.Query("GetLotsOfStuff", parameters,
    Query.Returns(OneToOne<Beer, Glass>.Records)
        .ThenChildren(Some<Napkin>.Records)
        .Then(Some<Wine>.Records));
var beer = results.Set1;
var glass = beer.Glass;
var napkins = beer.Napkins.ToList();
var wine = results.Set2;

But...but how? To that, I say: it's magic! Insight can decode the records and figure out one-to-one and parent-child relationships automatically. Almost all the time, it does this with no work or configuration on your part. But if you have a wacky model, there are plenty of non-scary ways to tell Insight how to work with your data. Read the wiki for details.

Full async support. Just add Async:

var task = c.QueryAsync<Beer>("FindBeer", new { Name = "IPA" });

Send whole lists of objects to databases that support table parameters. No more multiple queries or weird parameter mapping:

-- auto table parameters
CREATE TYPE BeerTable (Name [nvarchar](256), Flavor [nvarchar](256))
CREATE PROCEDURE InsertBeer (@BeerList [BeerTable])
List<Beer> beerList = new List<Beer>();
conn.Execute("InsertBeer", new { BeerList = beerList });

Insight can also stream objects over your database's BulkCopy protocol.

// auto bulk-copy objects
IEnumerable<Beer> beerList; // from somewhere
conn.BulkCopy("Beer", beerList);

Oh, wait. You want to inline your SQL. We do that too. Just add Sql.

var beerList = conn.QuerySql<Beer>("SELECT * FROM Beer WHERE Name LIKE @Name", new { Name = "%ipa%" });
conn.ExecuteSql ("INSERT INTO Beer VALUES (ID, Name)", beer);

Seriously, everything just works automatically. But if you really want to control every aspect of mapping, see the wiki.

Motto

Insight.Database is the .NET micro-ORM that nobody knows about because it's so easy, automatic, and fast, (and well-documented) that nobody asks questions about it on StackOverflow.

Licensing

Insight.Database is available under any of the following licenses:

  • The "Tell Everyone You Know How Awesome Insight Is" License
  • The "Answer Every Stackoverflow ORM question with 'Use Insight.Database'" License
  • The "Buy A Friend A Beer" License
  • The "Do Some Good" (Karmic) License
  • MS-Public License

Support Insight.Database

The best way is to buy my novel, and then leave a good review.

UNDO! The True Legend of Eugene the Misconceived

Or you can shop through my Amazon Affiliate Link: Amazon - Shop. Connect. Enjoy. All from Earth's Biggest Selection.

Go ahead. You know you need to buy something anyway...

Major Insight Releases

  • v5.0 - Composite keys, Deep parameter binding.
  • v4.0 - Read one-to-one, one-to-many, and many-to-many relationships automatically, with ways to extend it.
  • v3.0 - Support for most common database and tools. See the list of supported providers.
  • v2.1 - Automatically implement an interface with database calls.
  • v2.0 - Performance and asynchronous release.
  • v1.0 - Let the magic begin!

Documentation

Full documentation is available on the wiki