How to save a MySQL timestamp as a String instead of a DateTime using AutoMapper?
I'm using AutoMapper to save my MySQL results in a List, this is complete with information on when the row was last updated. The 'timestamp' will then be used to query the database for updates. But, I'm afraid that using C# DateTime type, will modify the timezone, depending on the location of the user. As I experienced this problem earlier in the development cycle.
So, basically my question is how do I make sure that the 'timestamp' saved using AutoMapper isn't modified and can be used again to query the database?
Edit: This is the code used to convert the results.
public class Entry
{
public UInt32 id { get; s开发者_JS百科et; }
public string ... { get; set; }
public UInt16 ... { get; set; }
public string ... { get; set; }
public string lastupdated { get; set; } // Using DateTime works, also tried value.ToString()
public string ... { get; set; }
public UInt16 ... { get; set; }
}
List<Entry> users = AutoMapper.Mapper.Map<MySqlDataReader,List<Entry>>(dbReader);
You can implement this using a custom formatter.
For more detail on how to implement such a formatter, see this article at CodeProject: http://www.codeproject.com/KB/codegen/automapperformatters.aspx.
精彩评论