Git Product home page Git Product logo

dapper.bulk's Introduction

Dapper.Bulk- bulk inserts for Dapper

Features

Dapper.Bulk contains helper methods for bulk inserting.

Download

Dapper.Bulk Nuget

PM> Install-Package Dapper.Bulk

Usage

  • Inserts entities, without result for best performance:
connection.BulkInsert(data);
await connection.BulkInsertAsync(data);
  • Inserts and returns inserted entities:
var inserted = connection.BulkInsertAndSelect(data);
var inserted = await connection.BulkInsertAndSelectAsync(data);

Default Conventions

  • TableName is TypeName + s. When Interface I is removed.
  • Key is Id property (case-insensitive)

Custom Conventions

TableName - somewhere before usage call.

TableMapper.SetupConvention("tbl", "s")

Attributes

We do not rely on specific attributes. This means you can use whatever attributes with following names:

  • TableAttribute - Must have string Name property. Exists in System.ComponentModel.DataAnnotations.Schema
  • ColumnAttribute - Must have string Name property. Exists in System.ComponentModel.DataAnnotations.Schema
  • KeyAttribute - Marking only attribute. Exists in System.ComponentModel.DataAnnotations.Schema
  • ComputedAttribute - Marking only attribute. For fields returned from Db.
  • NotMapped - Marking only attribute. For ignored fields.
// Table Cars by default convention 
public class Car
{
    // Identity by convention
    public int Id { get; set; }
    
    public string Name { get; set; }
	
    public DateTime ManufactureDate { get; set; }
}
// Supported in v1.2+
public enum CarType : int
{
    Classic = 1,
    Coupe = 2
}

[Table("tblCars")]
public class Car
{
    [Key] // Identity
    public int CarId { get; set; }
    
    public string Name { get; set; }
	
    public CarType CarType { get; set; } //SQL Data Type should match Enum type
	
    [Computed] // Will be ignored for inserts, but the value in database after insert will be returned
    public DateTime ManufactureDate { get; set; }
}
public class IdentityAndNotMappedTest
{
    [Key]
    public int IdKey { get; set; }

    public string Name { get; set; }

	// Will be ignored for inserts
    public virtual TestSublass TestSublass { get; set; }

    [NotMapped] // Will be ignored for inserts
    public int Ignored { get; set; }
}
 private class ColumnIsDifferent
{
    [Key]
    public int IdKey { get; set; }

    [Column("Name_1")]
    public string Name { get; set; }

    [Column("Int_Col")]
    public int IntCol { get; set; }

    [Column("Long_Col")]
    public long LongCol { get; set; }

    [NotMapped]
    public int Ignored { get; set; }
}

dapper.bulk's People

Contributors

crabyter avatar pew-er 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.