Skip to content
Browse files

Fix issue #171 (SqlBulkInserter does not use specified schema)

  • Loading branch information...
1 parent 1305aae commit 3f10a595c36e7234fbd83d9d54628ec49c8d4f91 @markrendle committed Mar 15, 2012
View
18 Simple.Data.BehaviourTest/BulkInsertTest.cs
@@ -11,11 +11,16 @@ public class BulkInsertTest : DatabaseIntegrationContext
protected override void SetSchema(MockSchemaProvider schemaProvider)
{
schemaProvider.SetTables(new[] { "dbo", "Users", "BASE TABLE" },
- new[] { "dbo", "NoIdentityColumnUsers", "BASE TABLE" });
+ new[] { "dbo", "NoIdentityColumnUsers", "BASE TABLE" },
+ new[] { "foo", "Users", "BASE TABLE" });
schemaProvider.SetColumns(new object[] { "dbo", "Users", "Id", true },
new[] { "dbo", "Users", "Name" },
new[] { "dbo", "Users", "Password" },
new[] { "dbo", "Users", "Age" },
+ new object[] { "foo", "Users", "Id", true },
+ new[] { "foo", "Users", "Name" },
+ new[] { "foo", "Users", "Password" },
+ new[] { "foo", "Users", "Age" },
new[] { "dbo", "NoIdentityColumnUsers", "Id" },
new[] { "dbo", "NoIdentityColumnUsers", "Name" },
new[] { "dbo", "NoIdentityColumnUsers", "Password" },
@@ -33,6 +38,17 @@ public void TestBulkInsertWithStaticTypeObjectAndIdentityColumn()
Parameter(1).Is(DBNull.Value);
Parameter(2).Is(42);
}
+
+ [Test]
+ public void TestBulkInsertWithStaticTypeObjectAndIdentityColumnOnSchemaQualifiedTable()
+ {
+ var users = new[] { new User { Name = "Steve", Age = 50 }, new User { Name = "Phil", Age = 42 }};
+ _db.foo.Users.Insert(users);
+ GeneratedSqlIs("insert into [foo].[Users] ([Name],[Password],[Age]) values (@p0,@p1,@p2)");
+ Parameter(0).Is("Phil");
+ Parameter(1).Is(DBNull.Value);
+ Parameter(2).Is(42);
+ }
[Test]
public void TestBulkInsertWithStaticTypeObjectAndIdentityColumnAndIdentityFunctionThatExpectsAValueSelects()
View
2 Simple.Data.SqlServer/SqlBulkInserter.cs
@@ -37,7 +37,7 @@ public class SqlBulkInserter : IBulkInserter
bulkCopy = new SqlBulkCopy(connection);
}
- bulkCopy.DestinationTableName = adapter.GetSchema().FindTable(tableName).ActualName;
+ bulkCopy.DestinationTableName = adapter.GetSchema().FindTable(tableName).QualifiedName;
using (connection.MaybeDisposable())
using (bulkCopy)
View
46 Simple.Data.SqlTest/BulkInsertTest.cs
@@ -0,0 +1,46 @@
+namespace Simple.Data.SqlTest
+{
+ using System.Collections.Generic;
+ using NUnit.Framework;
+
+ [TestFixture]
+ public class BulkInsertTest
+ {
+ [TestFixtureSetUp]
+ public void Setup()
+ {
+ DatabaseHelper.Reset();
+ }
+
+ [Test]
+ public void BulkInsertUsesSchema()
+ {
+ var db = DatabaseHelper.Open();
+ db.test.SchemaTable.DeleteAll();
+ db.test.SchemaTable.Insert(GenerateItems());
+
+ var list = db.test.SchemaTable.All().ToList();
+ Assert.AreEqual(1000, list.Count);
+ }
+
+ private static IEnumerable<SchemaItem> GenerateItems()
+ {
+ for (int i = 0; i < 1000; i++)
+ {
+ yield return new SchemaItem(i, i.ToString());
+ }
+ }
+ }
+
+ class SchemaItem
+ {
+ public SchemaItem(int id, string description)
+ {
+ Id = id;
+ Description = description;
+ }
+
+ public int Id { get; set; }
+ public string Description { get; set; }
+ }
+}
View
1 Simple.Data.SqlTest/Simple.Data.SqlTest.csproj
@@ -62,6 +62,7 @@
</CodeAnalysisDependentAssemblyPaths>
</ItemGroup>
<ItemGroup>
+ <Compile Include="BulkInsertTest.cs" />
<Compile Include="ConversionTests.cs" />
<Compile Include="DatabaseHelper.cs" />
<Compile Include="DatabaseOpenerTests.cs" />

0 comments on commit 3f10a59

Please sign in to comment.
Something went wrong with that request. Please try again.