I'm having a problem with Azure SQL server, on my local machine I can save a datetimeoffset into the db and the timezone offset is correctly saved like below
2017-03-31 00:00:00.0000000 -05:00
however on azure is losing the timezone offset, my columns are of datetimeoffset type and I'm getting my datetimeoffset using this DateTimeOffset.UtcNow.UtcDateTime
or DateTimeOffset.Now
but neither way seems to work, is always being saved like the below
2017-03-31 00:00:00.0000000 +00:00
how can I save the correct DateTimeOffset on Azure SQL server.
Edit: I'm using Entity Framework Code First Migration, I just create the entity and assign the DateTimeOffset using any of the line above and then context.SaveChanges().
var entity = Mapper.Map<CarSearchForm, CarSearches>(model);
ctx.CarSearches.Add(entity);
ctx.SaveChanges();
and then automapper profile is like this
CreateMap<CarSearchForm, CarSearches>()
.ForMember(dest => dest.RequestedDate, opts => opts.MapFrom(src => DateTimeOffset.UtcNow.UtcDateTime))
.ForMember(dest => dest.PickupTime, opts => opts.MapFrom(src => src.TimePickup))
.ForMember(dest => dest.DropoffTime, opts => opts.MapFrom(src => src.TimePickup));
Here is the Model
namespace Data.Entities
{
public class CarSearches
{
public int CarSearchesId { get; set; }
[Required]
public string PickupPlace { get; set; }
[Required]
public DateTimeOffset PickupDate { get; set; }
[Required]
public DateTimeOffset PickupTime { get; set; }
[Required]
public DateTimeOffset DropoffDate { get; set; }
[Required]
public DateTimeOffset DropoffTime { get; set; }
[Required]
public CarTransmission Transmission { get; set; }
[Required]
public DateTimeOffset RequestedDate { get; set; }
}
}
I'm only interested in the RequestedDate property above, I can't figure it out why is not saving the timezone offset on Azure but works locally.
Thanks