Skip to content

Missing Column on entity On Table - column has underscores and space #157

@JamesSkemp

Description

@JamesSkemp

We have a SQL Server table that uses underscores in the table and field names, and are attempting to using BulkInsert to add a number of records.

A combination of the following works fine for all columns except one:

BulkOperationManager.BulkOperationBuilder = operation => operation.MatchNamesWithUnderscores = true;
DapperPlusManager.Entity<TableName>().Table("dbo.TABLE_NAME");

The column that is not working includes a space in the column name, in addition to underscores. For example FAILING_COLUMN_ NAME.

If I add [System.ComponentModel.DataAnnotations.Schema.Column("FAILING_COLUMN_ NAME")] to the entity property, there's no errors, but the field values (for this column) also aren't saved to the database. All other fields in the table properly save.

If I update the DapperPlusManager above to the following (based upon https://dapper-plus.net/mapping#auto-mapping):

DapperPlusManager.Entity<TableName>().Table("dbo.TABLE_NAME")
    .Map(x => x.FailingColumnName, "FAILING_COLUMN_ NAME")
    .AutoMap()
                ;

Then I get the following error:

Missing Column : FAILING_COLUMN_ NAME
On entity : TableName
On Table : [dbo].[TABLE_NAME]

Partial stacktrace:

   at Z.BulkOperations.BulkOperation.()
   at Z.BulkOperations.BulkOperation.Execute()
   at Z.BulkOperations.BulkOperation.BulkInsert()
   at Z.Dapper.Plus.DapperPlusAction.Execute()
   at Z.Dapper.Plus.DapperPlusAction..ctor(BaseDapperPlusActionSet action, String key, DapperPlusActionKind kind, Object dataSource)
   at Z.Dapper.Plus.DapperPlusActionSet`1.AddAction(String mapperKey, DapperPlusActionKind actionKind, TEntity item)
   at Z.Dapper.Plus.DapperPlusActionSet`1.DapperPlusActionSetBuilder(DapperPlusContext context, IDbConnection connection, IDbTransaction transaction, String mapperKey, DapperPlusActionKind actionKind, TEntity item, Func`2[] selectors)
   at Z.Dapper.Plus.DapperPlusActionSet`1..ctor(DapperPlusContext context, IDbConnection connection, String mapperKey, DapperPlusActionKind actionKind, TEntity item, Func`2[] selectors)
   at Z.Dapper.Plus.DapperPlusExtensions.BulkInsert[T](IDbConnection connection, String mapperKey, T item, Func`2[] selectors)
   at Z.Dapper.Plus.DapperPlusExtensions.BulkInsert[T](IDbConnection connection, T item, Func`2[] selectors)
   [... calling custom code]

Throwing []s around the map - .Map(x => x.FailingColumnName, "[FAILING_COLUMN_ NAME]") and switching the order of .Map() and .AutoMap() (just in case) doesn't resolve the issue.

I'm able to query the table with that column name - select top 10 [FAILING_COLUMN_ NAME] from dbo.TABLE_NAME - so I know the column exists.

#82 (comment) does mention that all columns need to mapped, but given the date, and the link further above, it seems this is outdated. (The table also has 241 columns, so hoping I don't need to setup manual mapping for all of them.)

I also tried running BulkOperationManager.ClearInformationTableCache();, based upon https://github.com/zzzprojects/EntityFramework-Extensions/issues/313#issuecomment-571210415 mentioning cached table information, but that changed nothing.

What am I missing to help Dapper map the column for the insert?

Relevant versions:

  • .NET 8
  • Dapper 2.1.66
  • Z.Dapper.Plus 7.5.11

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions