zzzprojects / Bulk-Operations

C# SQL Bulk Operations | High-performance C# bulk insert, update, delete and merge for SQL Server, SQL Azure, SQL Compact, MySQL, and SQLite.
https://bulk-operations.net
142 stars 34 forks source link

Computed Column Mapping for BulkInsert #2

Closed HClausing closed 8 years ago

HClausing commented 8 years ago

Could you help me with How to Map a Computed Column?

I'm getting exception on BulkInsert.

Thanks.

zzzprojects commented 8 years ago

Hello @HClausing ,

If you want to map a computed column, I would assume you want to output the value?

Here is an example how to output value:

bulkOperation.ColumnMappings.Add("ComputedColumn", ColumnMappingDirectionType.Output);

If that's not what you are looking for, please provide me more information about what you want to achieve and/or the exception you receive.

Best Regards,

Jonathan

HClausing commented 8 years ago

Hello,

Thank you for the quick answer.

I have a computed column called "ClientToken" with SQL Formula [ID]+[Name], but no need the output value. I'm just using BulkInsert, and get theException. Maybe the raw sql is generating value for this column on INSERT, I believe.

Best Regards,

Henrique Clausing

zzzprojects commented 8 years ago

Are you using AutoMapping (not specifying any column)?

If yes, to solve this , issue, you will have to map every column but this one.

You can also use the "NotMapped" attribute on field/property you don't want to automap.

Let me know if this solution worked or it's something else.

Best Regards,

Jonathan

HClausing commented 8 years ago

It's working now!!

Yes, I'm using AutoMap, but after .BulkInsert command, I have added one instance of ColumnMapping with .Identity = True and fixed the problem!!

Thank you so much. This is an excelent library for Bulk Operations. 100k of rows on a large table (50 columns) done on a few minutes. Congratulations!

Best Regards,

Henrique Clausing

zzzprojects commented 8 years ago

That's great ;)

Make sure to join our newsletter

We are currently re-writing our library from scratch and soon we will ask all your help for the new API design && feature.

Best Regards,

Jonathan