Tips on how to use Dapper Plus in .NET Core

To put in these packages, choose the undertaking within the Resolution Explorer window, then right-click and choose “Handle NuGet Packages.” Within the NuGet Package deal Supervisor window, seek for the Dapper.Plus and Microsoft.Knowledge.Sqlite packages and set up them.

Alternatively, you possibly can set up the Dapper Plus and Dapper packages utilizing the NuGet Package deal Supervisor console by getting into the instructions beneath.


PM> Set up-Package deal Z.Dapper.Plus
PM> Set up-Package deal Dapper

Insert knowledge in bulk utilizing BulkInsert

To insert bulk knowledge (i.e., a number of entity data) in your database, you possibly can reap the benefits of the BulkInsert technique. This technique will insert a number of rows of knowledge within the underlying database desk . Allow us to look at the right way to use the BulkInsert technique to insert bulk knowledge in a database.

Take into account the next C# class.


class Writer
{
    public int AuthorId { get; set; }
    public string FirstName { get; set; } = string.Empty;
    public string LastName { get; set; } = string.Empty;
    public string Tackle { get; set; } = string.Empty;
    public string Cellphone { get; set; } = string.Empty;
}

The code given beneath illustrates how one can create an inventory of authors, populate knowledge, and return the record.


static Checklist GetAuthors()
{
    var authors = new Checklist()
    {
        new Writer() { AuthorId = 1, FirstName = "Joydip", LastName = "Kanjilal", Tackle = "Hyderabad, India", Cellphone = "1234567890" },
        new Writer() { AuthorId = 2, FirstName = "Steve", LastName = "Smith", Tackle = "Texas, USA", Cellphone = "0987654321" }
    };
    return authors;
}

You map your entity utilizing the DapperPlusManager.Entity technique as proven beneath. Word how the Identification extension technique has been referred to as to configure the identification column, i.e., AuthorId on this instance.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles