News

  • December 30th: Version 3.0 is released on CodePlex and NuGet. The documentation has been updated.
  • August 8th: Version 2.3 is released on CodePlex and NuGet. This release is available both as an assembly file and as a single source code file. PostgreSQL, SQLite and IBM DB2 are now supported. A select builder with paging support has been added. The documentation will soon be updated with more information on the new features.
  • June 3rd: Version 2.2.2 is released.
  • May 8th: Version 2.2 is released.
  • April 15th: Version 2.1 is out with support for MS Access.
  • Mar 12th: Version 2.0 is now out on CodePlex and NuGet.
  • Mar 3rd: FluentData is now available on NuGet.
  • Feb 28th: Version 1.2 of FluentData is out with support for QueryValues and automapping to enumerations.
  • Feb 19th: Version 1.1 of FluentData is out with support for MySQL.
  • Feb 14th: The first version (1.0) of FluentData is out on CodePlex.

Roadmap

About

Are you tired of fighting with overly complex ORMs such as Entity Framework and NHibernate? Are you tired of poorly generated SQL or having to change your business objects to work with your ORM? Do you miss the power and performance of ADO.NET and SQL, but not the manual tedious work? If so FluentData might be the framework for you.

FluentData is a Micro ORM that makes it simple to select, insert, update and delete data in a database. It gives the developer the power of ADO.NET but with the convenience of an ORM. It has a simple to use fluent API that uses SQL - the best and most suitable language to query data, and SQL or fluent builders to insert, update and delete data.

Features

Basic features

  • Supports the following databases
    • MS SQL Server
    • MS SQL Server Compact 4.0
    • MS SQL Azure
    • MS Access
    • Oracle
    • MySQL
    • SQLite
    • PostgreSQL
    • IBM DB2
  • Use SQL to select data, and SQL or fluent builders to insert, update and delete data.
  • Supports stored procedures.
  • Supports paging.
  • Queries are auto mapped or custom mapped to your own entity type (such as a Product type) or to a dynamic type (new in .NET 4.0).
  • Secure, use indexed or named parameters to prevent SQL injection.
  • Great performance.
  • Can work against any existing business objects and the business layer do not need any references to FluentData.
  • Available both as an assembly (.DLL) and as a single source code file.

Advanced features

  • Transactions
  • Multiple result set - Execute multiple queries as a single database hit for improved performance.
  • Custom return collections, e.g. ProductCollection instead of List<Product>.
  • Supports creation of complex entity objects through a custom Entity Factory.
  • Provider model that makes it easy to add support for other databases.

Contributions

Getting started

If you are using NuGet:
  • Search for FluentData and click Install.
If you are not using NuGet:
  1. Download the zip with the binary files.
  2. Extract it, and copy the files to your solution or project folder.
  3. Add a project reference to FluentData.dll.

If you use any other database than MS SQL Server or MS SQL Azure then make sure the right data provider is installed (see the Documentation tab for more information).

Code samples

The code samples below shows the most basic usage of FluentData. There are a lot more features but these are covered under the Documentation tab.

Import the namespace
use FluentData;

Create and initialize a DbContext
The code creates a DbContext and initializes it with the connection string from the *.config file.
private IDbContext Context()
{
	return new DbContext().ConnectionStringName("MyDatabase",
				new SqlServerProvider());
}

Get a single product
The query methods supports auto mapping or custom mapping to entity type or a dynamic type (new in C# 4.0).
Product product = Context().Sql(@"select * from Product
				where ProductId = 1").QuerySingle<Product>();

Get a list of products
The Query method can either return the data as a List<T> or as your own custom collection.
List<Product> products = Context().Sql(@"select * from Product;").Query<Product>();

Multiple result sets
FluentData supports multiple resultsets. This allows you to do multiple queries in a single database call.
using (var command = Context().MultiResultSql())
{
	List<Category> categories = command.Sql(
			@"select * from Category;
			select * from Product;").Query<Category>();

	List<Product> products = command.Query<Product>();
}

Insert a new product
Insert statements can be created using a builder:
var productId = Context().Insert("Product")
				.Column("Name", "The Warren Buffet Way")
				.Column("CategoryId", 1)
				.ExecuteReturnLastId();

or by using SQL:
var productId = Context().Sql(@"insert into Product(Name, CategoryId)
					values('The Warren Buffet Way', 1);").ExecuteReturnLastId();

Update an existing product
Update statements can be created using a builder:
Context().Update("Product")
		.Column("Name", "The Warren Buffet Way")
		.Column("CategoryId", 1)
		.Where("ProductId", 1)
		.Execute();

or by using SQL:
Context().Sql(@"update Product	set Name = 'The Warren Buffet Way', CategoryId = 1
	where ProductId = 1").Execute();

Delete an existing product
Delete statements can be created using a builder:
Context().Delete("Product").Where("ProductId", 1).Execute();

or by using SQL:
Context().Sql("delete from Product where ProductId = 1").Execute();

Parameters
To improve security and prevent what is known as SQL injection then parameters must be used. Both indexed parameters:
Product product = Context().Sql(@"select *	from Product
				where ProductId = @0", 1).QuerySingle<Product>();

and named parameters are supported:
Product product = Context().Sql(@"select * from Product where ProductId = @ProductId") 	
				.Parameter("ProductId", 1).QuerySingle<Product>();

Transactions
using (var context = Context().UseTransaction)
{
	context.Sql("update Product set Name = @0 where ProductId = @1")
				.Parameters("The Warren Buffet Way", 1)
				.Execute();

	context.Sql("update Product set Name = @0 where ProductId = @1")
				.Parameters("Bill Gates Bio", 2)
				.Execute();

	context.Commit();
}

Check the Documentation for more code samples

Last edited Thu at 10:01 AM by roydux, version 57