diff --git a/SqlBulkTools.IntegrationTests/Model/Book.cs b/SqlBulkTools.IntegrationTests/Model/Book.cs index b8f95b1..c97b798 100644 --- a/SqlBulkTools.IntegrationTests/Model/Book.cs +++ b/SqlBulkTools.IntegrationTests/Model/Book.cs @@ -26,6 +26,8 @@ public class Book [Required] [Index] public decimal? Price { get; set; } + + public float? TestFloat { get; set; } } } diff --git a/SqlBulkTools.IntegrationTests/Scripts/TestDataTypesTable.sql b/SqlBulkTools.IntegrationTests/Scripts/TestDataTypesTable.sql new file mode 100644 index 0000000..10245b9 --- /dev/null +++ b/SqlBulkTools.IntegrationTests/Scripts/TestDataTypesTable.sql @@ -0,0 +1,21 @@ +CREATE TABLE [dbo].[TestDataTypes] +( +FloatTest float(24), +FloatTest2 float, +DecimalTest decimal(14,2), +MoneyTest money, +SmallMoneyTest smallmoney, +NumericTest numeric(30,2), +RealTest real, +DateTimeTest datetime, +DateTime2Test datetime2, +SmallDateTimeTest smalldatetime, +DateTest date, +TimeTest time, +GuidTest uniqueidentifier, +TextTest text, +VarBinaryTest varbinary(20), +BinaryTest binary(10), +TinyIntTest tinyint, +BigIntTest bigint +); \ No newline at end of file diff --git a/SqlBulkTools.IntegrationTests/SqlBulkToolsIT.cs b/SqlBulkTools.IntegrationTests/SqlBulkToolsIT.cs index 9b2d2bc..1c2b32a 100644 --- a/SqlBulkTools.IntegrationTests/SqlBulkToolsIT.cs +++ b/SqlBulkTools.IntegrationTests/SqlBulkToolsIT.cs @@ -632,6 +632,29 @@ public void SqlBulkTools_BulkInsertOrUpdate_DecimalValueCorrectlySet() } + [Test] + public void SqlBulkTools_BulkInsertOrUpdae_FloatValueCorrectlySet() + { + _db.Books.RemoveRange(_db.Books.ToList()); + _db.SaveChanges(); + + float? expectedFloat = (float?)1.33; + + BulkOperations bulk = new BulkOperations(); + List books = new List() { new Book() { Description = "Test", ISBN = "12345678910", Price = 30, TestFloat = expectedFloat} }; + + bulk.Setup(x => x.ForCollection(books)) + .WithTable("Books") + .AddAllColumns() + .BulkInsertOrUpdate() + .MatchTargetOn(x => x.ISBN) + .SetIdentityColumn(x => x.Id); + + bulk.CommitTransaction("SqlBulkToolsTest"); + + Assert.AreEqual(_db.Books.First().TestFloat, expectedFloat); + } + private void AppendToLogFile(string text) { diff --git a/SqlBulkTools/BulkOperationsHelpers.cs b/SqlBulkTools/BulkOperationsHelpers.cs index 90056a5..2c4f494 100644 --- a/SqlBulkTools/BulkOperationsHelpers.cs +++ b/SqlBulkTools/BulkOperationsHelpers.cs @@ -37,7 +37,10 @@ internal string BuildCreateTempTable(HashSet columns, DataTable schema, actualColumns.Add(row["COLUMN_NAME"].ToString(), row["DATA_TYPE"].ToString()); - if (columnType == "varchar" || columnType == "nvarchar") + if (columnType == "varchar" || columnType == "nvarchar" || + columnType == "char" || columnType == "binary" || + columnType == "varbinary") + { actualColumnsMaxCharLength.Add(row["COLUMN_NAME"].ToString(), row["CHARACTER_MAXIMUM_LENGTH"].ToString());