Giter Site home page Giter Site logo

ayberkcanturk / dapper.tablevaluedparameter Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 1.0 44 KB

An extension to provide Table-Valued Parameters to Dapper. .NET Core support available!

License: MIT License

C# 79.97% PowerShell 19.15% Batchfile 0.87%
dapper dapper-extensions dapper-dot-net tablevaluedparameter tvp dotnetcore dotnet-core2 nuget

dapper.tablevaluedparameter's Introduction

Dapper.TableValuedParameter Build status

Installation NuGet version

It's as easy as PM> Install-Package Dapper.TableValuedParameter from nuget

Quick Start

Pass your "Tvp" class instance as a parameter to Dapper Query method.

Just an example;

	CREATE TYPE dbo.SaleOrderDetailType AS TABLE  
	( UnitPrice MONEY, OrderQty INT ) 
    
    	CREATE PROCEDURE [dbo].[GetSaleOrderDetail] @SaleOrderDetail dbo.[SaleOrderDetailType] READONLY
	AS
	BEGIN
			SELECT 
					SOD.UnitPrice, 
					SOD.OrderQty
			FROM 
					SaleOrderDetail AS SOD WITH(NOLOCK) 
					WHERE SOD.UnitPrice = @UnitPrice AND SOD.OrderQty = @OrderQty
	END    
	public class SaleOrderDetailTypeDto()
	{
		[Column(Name:"SellingPrice")]
		[Map(SqlDbType.Money)] //.NET framework data type has more than one possibility in SqlDbType such as decimal, money,smallmoney etc. So we have to explictly it.
		public decimal Price { get; set; } 

		public int OrderQty { get; set; } //It  will be automatically mapped to SqlDbType.Int
	}

	using (IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["AdventureWorks"].ConnectionString))
	{
		IEnumerable<SaleOrderDetailTypeDto> tvpDto = new List<SaleOrderDetailTypeDto>()
		{
		... //This is the parameter which is going to be projected to your table-valued parameter.
		};

		return db.Query<SaleOrderDetail>("dbo.GetSaleOrderDetail", new Tvp("@SaleOrderDetail", "dbo.SaleOrderDetailType", tvpDto), commandType: CommandType.StoredProcedure).ToList(); 
    }

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.