Code Monkey home page Code Monkey logo

express-data-library's Introduction

Express.Data

If your project needs to fire queries to a relational database often at different places of your code. This lightweight library will be helpfull.

Express.Data allows playing with database queries easy by making use of Dapper, DapperContrib and DTO classes. Examples are provided below. This library is a wrapper around the popular Dapper micro ORM and it's extension Dapper.Contrib. It works with any relational database and runs over ADO.NET and DapperMicroORM

The library exposes easy to use API for all kind of database CRUD operations.

alt text

Package Manager

The library is available free on NuGet https://www.nuget.org/packages/Twileloop.ExpressData

Install-Package Twileloop.ExpressData -Version 1.0.0

Versions

Version Information

Version Change log
v1.1 Basic CRUD Operations support

Repository Contents

This repo maintains 2 projects. The main library and a demo project to implement it

PreRequesties

Before running the demo program

  1. Create a table named tblUsers
  2. Create 3 columns Id, Fname and Lname
  3. Set the connection string to database server inside Main()

Usage

C# POCO Model building. The model should be decorated with Dapper.Contrib attributes for proper working. Here is an example

using Dapper.Contrib.Extensions;

namespace Demo
{
    [Table("tblUser")]
    public class tblUser
    {
        [Key]
        public int Id { get; set; }
        public string FName { get; set; }
        public string LName { get; set; }
        [Computed]
        public string Fullname { get; set; }
    }
}

Insert a model

var record = new tblUser {
	Id = 1,
	FName = "Sangeeth",
	LName = "Nandakumar"
};
var primaryKey = SqlHelper.Insert < tblUser > (record, _connectionString);

Update a model

record = new tblUser {
	Id = 1,
	FName = "Navaneeth",
	LName = "Nandakumar"
};
var isUpdated = SqlHelper.Update < tblUser > (record, _connectionString);

Run a query

var sql1 = $ "SELECT * FROM tblUser WHERE Id=1";
var result = SqlHelper.Query < tblUser > (sql1, _connectionString).FirstOrDefault();

Run a safe query (Parameterised query)

var sql2 = $ "SELECT * FROM tblUser WHERE Id=@id AND Fname=@fname";
result = SqlHelper.QuerySafe < tblUser > (sql2, new {
	id = 1,
	fname = "Navaneeth"
},
_connectionString);

Run a stored procedure

var procedureName = $ "spGetUsers";
result = SqlHelper.Execute < tblUser > (procedureName, new {
	id = 1
},
_connectionString).FirstOrDefault();

express-data-library's People

Contributors

sangeethnandakumar avatar

Stargazers

 avatar

Watchers

 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.