3

When I try to run, I get this error:

System.Data.SqlClient.SqlException: 'The definition for column 'Column' must include a data type

but I defined the types of variables in the 'business' class

public void import (String TXT_T_NEG, String TXT_ACAO, String TXT_ESPEC_PAPL, String Txt_num_neg, String Id_usr)
{
        lista.Add (new business(TXT_T_NEG, TXT_ACAO, TXT_ESPEC_PAPL, Txt_num_neg, Id_usr)
}

public void bulkupdate ()
{
        var bulk = new BulkOperations ();

        using (TransactionScope trans = new TransactionScope ())
        {
            using (SqlConnection cone = new SqlConnection (@"Myconnection"))   
            {
                bulk.Setup <business> ()
                .ForCollection (lista)
                .WithTable ("table")
                .AddColumn (x => x.Txt_t_neg)
                .AddColumn (x => x.Txt_acao)
                .AddColumn (x => x.Txt_espec_papl)
                .BulkUpdate ()
                .MatchTargetOn (x => x.Txt_num_neg)
                .MatchTargetOn (x => x.Id_usr)
                .Commit (cone);
            }
            trans.Complete ();
        }
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

This exception is raised when there's a discrepancy between a property name in your class and the corresponding database column. The library queries the table schema and then uses that to build a temporary table, but if the column and property names don't match, the temporary table creation statement will fail as it can't specify the correct data types.

In such cases, as explained in the library documentation, you must define a custom mapping by providing the column name, e.g.

.AddColumn(x => x.Id_usr, "Id")
Genyus
  • 28
  • 5