Skip to content

Commit

Permalink
Preparing test table.
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Taylor committed Aug 11, 2016
1 parent fd4198f commit d33329b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
2 changes: 2 additions & 0 deletions SqlBulkTools.IntegrationTests/Model/Book.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class Book
[Required]
[Index]
public decimal? Price { get; set; }

public float? TestFloat { get; set; }
}

}
21 changes: 21 additions & 0 deletions SqlBulkTools.IntegrationTests/Scripts/TestDataTypesTable.sql
Original file line number Diff line number Diff line change
@@ -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
);
23 changes: 23 additions & 0 deletions SqlBulkTools.IntegrationTests/SqlBulkToolsIT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Book> books = new List<Book>() { new Book() { Description = "Test", ISBN = "12345678910", Price = 30, TestFloat = expectedFloat} };

bulk.Setup<Book>(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)
{
Expand Down
5 changes: 4 additions & 1 deletion SqlBulkTools/BulkOperationsHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ internal string BuildCreateTempTable(HashSet<string> 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());
Expand Down

0 comments on commit d33329b

Please sign in to comment.