Coder Social home page Coder Social logo

dapper-fluent's Introduction

Dapper Fluent API

Dapper.Fluent is a small and easy library that supports fluent API for query construction and execution over database connection using Dapper.Net.

Core Features

  • Fluent interface, an object oriented API that aims to provide readable code.
  • Usage the full power of Dapper.Net in elegant way.
  • Implementation of API close to BLToolkit ORM API.

Overview

Fluent API

IDbManager SetCommand(string commandText);
IDbManager SetCommand(string commandText, object parameters);
IDbManager SetSpCommand(string commandText);
IDbManager SetSpCommand(string commandText, object parameters);
IDbManager SetParameter(string name, object value);
IDbManager SetParameter(string name, DbType dbType, ParameterDirection direction);
IDbManager SetParameter(string name, object value, DbType dbType, ParameterDirection direction);
IDbManager SetParameter(string name, object value, DbType dbType, ParameterDirection direction, int? size);
IDbManager SetParameters(object value);

Transactions support

void BeginTransaction();
void BeginTransaction(IsolationLevel isolationLevel);
void CommitTransaction();
void RollbackTransaction();

Querying

int Execute();
T ExecuteObject<T>() where T : class;
IEnumerable<T> ExecuteList<T>() where T : class;
Tuple<IEnumerable<T1>, IEnumerable<T2>> ExecuteMultiple<T1, T2>();
Tuple<IEnumerable<T1>, IEnumerable<T2>, IEnumerable<T3>> ExecuteMultiple<T1, T2, T3>();
IEnumerable<TResult> ExecuteMapping<T1, T2, TResult>(Func<T1, T2, TResult> map, string splitOn);
IEnumerable<TResult> ExecuteMapping<T1, T2, T3, TResult>(Func<T1, T2, T3, TResult> map, string splitOn);
IEnumerable<TResult> ExecuteMapping<T1, T2, T3, T4, TResult>(Func<T1, T2, T3, T4, TResult> map, string splitOn);
IEnumerable<TResult> ExecuteMapping<T1, T2, T3, T4, T5, TResult>(Func<T1, T2, T3, T4, T5, TResult> map, string splitOn);
IEnumerable<TResult> ExecuteMapping<T1, T2, T3, T4, T5, T6, TResult>(Func<T1, T2, T3, T4, T5, T6, TResult> map, string splitOn);

Examples usage

Setting up fluent API context:

DbProviderFactory factory = DbProviderFactories.GetFactory(providerName);
IDbConnection connection = factory.CreateConnection();

Querying for post by id using stored procedure:

using(IDbManager dbManager = new DbManager(connection))
{
	Post post = dbManager.SetSpCommand("sp_Posts_FindById", new { @id = id })
    				.ExecuteObject<Post>();
}    

Querying for posts published for the last 7 days:

using(IDbManager dbManager = new DbManager(connection))
{
	IEnumerable<Post> posts = dbManager.SetCommand("SELECT * FROM [dbo].[Posts] WHERE [PublishedOn] BETWEEN @StartDate AND @EndDate AND [Status] = @Status")
    							.SetParameter("StartDate", DateTime.UtcNow.AddDays(-7))
    							.SetParameter("EndDate", DateTime.UtcNow)
    							.SetParameter("Status", (byte)Status.Active)
    							.ExecuteList<Post>();
}

dapper-fluent's People

Contributors

beardeddev avatar

Stargazers

 avatar Taylor Buchanan avatar Simon Geering avatar Gabe Chavez avatar  avatar hby avatar  avatar Sean G. Wright avatar Chung Trịnh avatar 曹文忠 avatar  avatar 刘裕惠 avatar Marcos Lima avatar 汤姆大叔 avatar  avatar  avatar Matthew Levandowski avatar  avatar Jia-Rui Lin avatar  avatar Jason Finch avatar Sergei Shvec avatar

Watchers

 avatar Liviu avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.