zzzprojects / Dapper-Plus

Dapper Plus - High-Efficient Bulk Actions (Insert, Update, Delete, and Merge) for .NET
https://dapper-plus.net/
380 stars 84 forks source link

Bulk Insert throws the exception 'Unknown data type' whenever inserting GUID to MySQL #141

Closed thtung2901 closed 5 months ago

thtung2901 commented 5 months ago

Description

It throws an exception when I try to bulk insert customer data with the GUID attribute type into my MySQL database. These properties map to the binary(16) column type in the DB.

I also tried to change the GUID type to byte array and string. It still throws the same exception. Only when ignoring fields of binary type db(16) will the bulk import work.

Exception

image

MySql.Data.MySqlClient.MySqlException
  HResult=0x80004005
  Message=Unknown data type
  Source=MySql.Data
  StackTrace:
   at MySql.Data.MySqlClient.MySqlField.GetIMySqlValue(MySqlDbType type)
   at MySql.Data.MySqlClient.MySqlParameter.SetMySqlDbType(MySqlDbType mysqlDbtype)
   at .( , DbCommand , String )
   at .( , DbCommand )
   at .Execute(List`1 actions)
   at Z.BulkOperations.BulkOperation.Execute()
   at Z.Dapper.Plus.DapperPlusAction.Execute()
   at Z.Dapper.Plus.DapperPlusAction..ctor(BaseDapperPlusActionSet action, String key, DapperPlusActionKind kind, Object dataSource)
   at Z.Dapper.Plus.DapperPlusActionSet`1.AddAction(String mapperKey, DapperPlusActionKind actionKind, TEntity item)
   at Z.Dapper.Plus.DapperPlusActionSet`1.DapperPlusActionSetBuilder(DapperPlusContext context, IDbConnection connection, IDbTransaction transaction, String mapperKey, DapperPlusActionKind actionKind, TEntity item, Func`2[] selectors)
   at Z.Dapper.Plus.DapperPlusExtensions.BulkInsert[T](IDbConnection connection, String mapperKey, T item, Func`2[] selectors)
   at Z.Dapper.Plus.DapperPlusExtensions.BulkInsert[T](IDbConnection connection, T item, Func`2[] selectors)
   at Program.<Main>$(String[] args) in C:\Users\tung.hoang\source\repos\test-bulk\Program.cs:line 42

Fiddle or Project (Optional)

C# model:

public class CustomerPartialModel
{
    [Key]
    public int Id { get; set; }
    public string CustomerCode { get; set; }
    public string CompanyName { get; set; }
    public string DisplayName { get; set; }
    public Guid CustomerId { get; set; }
    public Guid CompanyId { get; set; }
    public DateTime? CreatedDateTime { get; set; }
    public DateTime? UpdateDateTime { get; set; }
}

Table creating query:

CREATE TABLE `customerpartial` (
  `Id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `CustomerCode` varchar(40) NOT NULL,
  `CustomerId` binary(16) DEFAULT NULL,
  `CompanyName` varchar(160) DEFAULT NULL,
  `DisplayName` varchar(160) DEFAULT NULL,
  `CompanyId` binary(16) DEFAULT NULL,
  `CreatedDateTime` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
  `UpdateDateTime` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
  PRIMARY KEY (`Id`),
  KEY `idx_customerpartial_CustomerCode` (`CompanyId`, `CustomerCode`),
  KEY `idx_customerpartial_DisplayName` (`CompanyId`, `DisplayName`),
  KEY `idx_customerpartial_CustomerId` (`CustomerId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

Further technical details

JonathanMagnan commented 5 months ago

Hello @thtung2901 ,

Thank you for reporting, my developer will look at it and let you know if more information is required.

I know that we solved 2 months ago a similar issue on EF Core, but it was more related to a missing converter. On Dapper Plus, we probably never supported this type for MySQL yet.

Best Regards,

Jon

JonathanMagnan commented 5 months ago

Hello @thtung2901 ,

We tried your scenario with the same Dapper Plus and MySql.Data versions, but everything worked as expected.

You can see my developer test in this attachment: mysql_guidissue.txt

Could you try his test and let us know if that's working for you? If you find out he missed something, just let us know.

Best Regards,

Jon

JonathanMagnan commented 5 months ago

Hello @thtung2901,

Since our last conversation, we haven't heard from you.

Let me know if you need further assistance.

Best regards,

Jon

JonathanMagnan commented 5 months ago

Hello @thtung2901

Unfortunately, since we didn't hear from you I will close this issue.

As previously mentioned, we need a runnable project to be able to assist you.

We will reopen the issue if a project is received.

Feel free to contact us for questions, issues or feedback.

Best Regards,

Jon