When Culture is set dates formatted incorectly
Posted: Wed 10 Feb 2016 17:41
If the 'CurrentCulture' is set on the 'Thread' than the devart driver passes dates to the database in that culture. When a culture that uses a different date format than mysql than the database throws a date format is incorrect error. For example:
Is there a way to make the driver pass dates in a culture agnostic manner. I think this should be a bug because mysql requires a standard format for date storage. The driver should explicitly output in that format not whatever culture or format is set in the program.
Code: Select all
string culture = "AR";
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(culture);
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
using (AuthContext context = new AuthContext())
{
try
{
User user = await context.Users.SingleOrDefaultAsync(u => u.ID == userId);
user.InterestedInReceivingCommunications = !user.InterestedInReceivingCommunications;
user.ModifiedDate = DateTime.UtcNow;
context.Users.Attach(user);
context.Entry(user).State = EntityState.Modified;
await context.SaveChangesAsync();
}
catch (Exception e)
{
Console.WriteLine(e);
}
}