igor-tkachev / bltoolkit

Business Logic Toolkit for .NET
MIT License
297 stars 112 forks source link

MySQL DateTime? with InsertBatch #405

Closed comik closed 6 years ago

comik commented 6 years ago

Batch insert attempts with nullable DateTime produce exceptions like "Incorrect datetime value: '2' for column '' at row 1". I'm curiuous on how could it produce 2 out of DateTime object. Also noticed that if you change current thread culture info, the "value" changes too. With that being said, it also maps successfuly when single Insert called. (Have a code that splits lits by 2 down to single item on fails, thus I found out this unexpected behaviour). If somebody aware of this issue and has solution for that, would be highly appreciated!

sdanyliv commented 6 years ago

@comik, i'm not BLToolkit guy but simple analysis shows that you have to override in MySqlDataProvider function SetParameterValue and process DateTime? type accordingly

public override void SetParameterValue(IDbDataParameter parameter, object value)
{
    if (value is DateTime?)
    ....
    else
        base.SetParameterValue(parameter, value);

}

If you provide us with Pull Request with appropriate fix, i hope @ili or @igor-tkachev will merge your changes and release new version.

comik commented 6 years ago

Worked like a charm! Thank you very much!