@@ -557,6 +557,90 @@ public void BulkCopyDataTableWithMySqlDecimal()
557557 Assert . Equal ( "3.579" , reader . GetMySqlDecimal ( 0 ) . ToString ( ) . TrimEnd ( '0' ) ) ;
558558 }
559559 }
560+
561+ #if NET6_0_OR_GREATER
562+ [ Fact ]
563+ public void BulkCopyDataTableWithDateOnly ( )
564+ {
565+ var dataTable = new DataTable ( )
566+ {
567+ Columns =
568+ {
569+ new DataColumn ( "id" , typeof ( int ) ) ,
570+ new DataColumn ( "date1" , typeof ( DateOnly ) ) ,
571+ } ,
572+ Rows =
573+ {
574+ new object [ ] { 1 , new DateOnly ( 2021 , 3 , 4 ) } ,
575+ } ,
576+ } ;
577+
578+ using var connection = new MySqlConnection ( GetLocalConnectionString ( ) ) ;
579+ connection . Open ( ) ;
580+ using ( var cmd = new MySqlCommand ( @"drop table if exists bulk_load_data_table;
581+ create table bulk_load_data_table(a int, date1 date);" , connection ) )
582+ {
583+ cmd . ExecuteNonQuery ( ) ;
584+ }
585+
586+ var bulkCopy = new MySqlBulkCopy ( connection )
587+ {
588+ DestinationTableName = "bulk_load_data_table" ,
589+ } ;
590+ var result = bulkCopy . WriteToServer ( dataTable ) ;
591+ Assert . Equal ( 1 , result . RowsInserted ) ;
592+ Assert . Empty ( result . Warnings ) ;
593+
594+ using ( var cmd = new MySqlCommand ( @"select * from bulk_load_data_table;" , connection ) )
595+ {
596+ using var reader = cmd . ExecuteReader ( ) ;
597+ Assert . True ( reader . Read ( ) ) ;
598+ Assert . Equal ( new DateOnly ( 2021 , 3 , 4 ) , reader . GetDateOnly ( 1 ) ) ;
599+ }
600+ }
601+
602+ [ Fact ]
603+ public void BulkCopyDataTableWithTimeOnly ( )
604+ {
605+ var dataTable = new DataTable ( )
606+ {
607+ Columns =
608+ {
609+ new DataColumn ( "id" , typeof ( int ) ) ,
610+ new DataColumn ( "time1" , typeof ( TimeOnly ) ) ,
611+ new DataColumn ( "time2" , typeof ( TimeOnly ) ) ,
612+ } ,
613+ Rows =
614+ {
615+ new object [ ] { 1 , new TimeOnly ( 1 , 2 , 3 , 456 ) , new TimeOnly ( 1 , 2 , 3 , 456 ) } ,
616+ } ,
617+ } ;
618+
619+ using var connection = new MySqlConnection ( GetLocalConnectionString ( ) ) ;
620+ connection . Open ( ) ;
621+ using ( var cmd = new MySqlCommand ( @"drop table if exists bulk_load_data_table;
622+ create table bulk_load_data_table(a int, time1 time, time2 time(3));" , connection ) )
623+ {
624+ cmd . ExecuteNonQuery ( ) ;
625+ }
626+
627+ var bulkCopy = new MySqlBulkCopy ( connection )
628+ {
629+ DestinationTableName = "bulk_load_data_table" ,
630+ } ;
631+ var result = bulkCopy . WriteToServer ( dataTable ) ;
632+ Assert . Equal ( 1 , result . RowsInserted ) ;
633+ Assert . Empty ( result . Warnings ) ;
634+
635+ using ( var cmd = new MySqlCommand ( @"select * from bulk_load_data_table;" , connection ) )
636+ {
637+ using var reader = cmd . ExecuteReader ( ) ;
638+ Assert . True ( reader . Read ( ) ) ;
639+ Assert . Equal ( new TimeOnly ( 1 , 2 , 3 ) , reader . GetTimeOnly ( 1 ) ) ;
640+ Assert . Equal ( new TimeOnly ( 1 , 2 , 3 , 456 ) , reader . GetTimeOnly ( 2 ) ) ;
641+ }
642+ }
643+ #endif
560644#endif
561645
562646 [ Fact ]
0 commit comments