TempTables with two strings are not working
stevencasburn opened this issue · 2 comments
Hello,
I want to use two strings in a TempTable, so in "OnModelCreatingPartial" I am publishing the following TempTables.
modelBuilder.ConfigureTempTable<string, string>(isKeyless: true);
(Tried it with and without "isKeyless").
Later in my Service I am using that like:
var twoStringsList = whatever
.Select(w => ( w.FirstString, w.SecondString )
.ToList();
await using ITempTableQuery<TempTable<string, string>> tempTableQuery =
await _ctx.BulkInsertValuesIntoTempTableAsync(twoStringsList);
This causes the following exception:
Column 'Column1' in table '#TempTable<string, string>_1' is of a type that is invalid for use as a key column in an index.
Could not create constraint or index. See previous errors.
Is this the expected behaviour?
Yes, for MS SQL Server the creation of a PK is enabled by default. I'm planing to disable it in V3 (which is for EF 5.0) by default - which will be a breaking change - to prevent this confusion.
You can disable the creation of PK using SqlServerTempTableBulkInsertOptions
await using ITempTableQuery<TempTable<string, string>> tempTableQuery =
await _ctx.BulkInsertValuesIntoTempTableAsync(twoStringsList, new SqlServerTempTableBulkInsertOptions()
{
PrimaryKeyCreation = SqlServerPrimaryKeyCreation.None
});
Awesome. Thank you for the fast answer!
Helped me a lot!
The creation of a default PK is agreed tricky when every datatype is allowed. Looking forward to V3!
Thanks
Steven