Giter Site home page Giter Site logo

IGNORE is supported? about dapper-plus HOT 3 CLOSED

zzzprojects avatar zzzprojects commented on July 28, 2024
IGNORE is supported?

from dapper-plus.

Comments (3)

JonathanMagnan avatar JonathanMagnan commented on July 28, 2024 3

Hello @CRC32EX ,

Here is the code you can use which will do the same behavior:

DapperPlusManager.Entity<EntitySimple>().Table("users").Key(x => x.ID, "id"); 

var users = new List<User>()
{
  new User{ Id = 2, Name = "swan" },
  new User{ Id = 4, Name = "bear" }
};
 
conn.UseBulkOptions(x => x.InsertIfNotExists = true).BulkInsert(users);

It doesn't use the IGNORE keyword but instead, check if the data already exists or not.

Is that an alternative solution that could work for you?

Best Regards,

Jon

from dapper-plus.

JonathanMagnan avatar JonathanMagnan commented on July 28, 2024

Hello @CRC32EX ,

It's currently not supported. I will look with my developer how we could support it.

Best Regards,

Jon

from dapper-plus.

CRC32EX avatar CRC32EX commented on July 28, 2024

It works well.
In my situation IGNORE is not needed anymore.
When I really needed IGNORE keyword, i will open this issue again.

In my situation, Key attributes also works well.

Thank you.

using MySqlConnector;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Z.Dapper.Plus;

namespace Test
{
  [Table("users")]
  class User
  {
    [Key]
    [Column("id")]
    public ulong Id { get; set; }

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

  class Program
  {
    const string Connstr = "userid=root;password=MYPASSWORD;database=MYDB;Host=127.0.0.1;";

    static MySqlConnection Connect()
    {
      var conn = new MySqlConnection(Connstr);
      conn.Open();
      return conn;
    }

    static void Main()
    {
      using var conn = Connect();

      var users = new List<User>()
      {
        new User { Id = 2, Name = "swan" },
        new User { Id = 4, Name = "bear" }
      };

      conn.UseBulkOptions(x => x.InsertIfNotExists = true).BulkInsert(users);
    }
  }
}

from dapper-plus.

Related Issues (20)

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.