在ASP.NET ABP中,可以使用DateTimeOffset类型来存储和检索ISO日期时间(非本地时间)。下面是一个示例代码:
public class MyEntity : Entity
{
// other properties
public DateTimeOffset DateTime { get; set; }
}
public override void Up()
{
// other column definitions
CreateTable(
"MyEntities",
c => new
{
// other column definitions
DateTime = c.DateTimeOffset(nullable: false, precision: 7)
})
.PrimaryKey(t => t.Id);
}
public class MyEntityAppService : ApplicationService, IMyEntityAppService
{
private readonly IRepository _myEntityRepository;
public MyEntityAppService(IRepository myEntityRepository)
{
_myEntityRepository = myEntityRepository;
}
public async Task> GetAllAsync()
{
var entities = await _myEntityRepository.GetAllListAsync();
return ObjectMapper.Map>(entities);
}
}
这样,就可以从数据库中返回一个ISO日期时间(非本地时间)。