I'm trying to insert a list of file names into a simple Sql Server table.
I'm trying to leverage SqlBulkCopy and @markgravell's FastMember library, as suggested by other SO answers.
public async Task AddFileNamesAsync(string[] fileNames)
{
fileNames.ShouldNotBeNull();
using (var bulkCopy = new SqlBulkCopy(ConnectionString))
{
using (var reader = ObjectReader.Create(fileNames))
{
bulkCopy.DestinationTableName = "FileNames";
bulkCopy.ColumnMappings.Add("value", "FileName");
await bulkCopy.WriteToServerAsync(reader)
.ConfigureAwait(false);
}
}
}
CREATE TABLE [dbo].[FileNames](
[FileNameId] [int] IDENTITY(1,1) NOT NULL,
[FileName] [varchar](500) NOT NULL
So I feel like it's a mapping issue either with:
- FastMember not able to map to some internal backing collection
- The FastMember backing collection doesn't have the same name as the DB column so it can't map.