【发布时间】:2023-03-29 08:02:01
【问题描述】:
我正在使用 MongoDB,并且发现了奇怪的行为(至少对我而言)。从 C# 插入并从 MongoDB 检索时,我得到了时差。
我的实体:
[BsonId]
public ObjectId Id { get; set; }
public bool IsActive { get; set; }
public string CreatedBy { get; set; }
public DateTime CreatedTime { get; set; }
public string Name { get; set; }
使用以下代码插入时间戳:
public bool Insert(AccountCategories _input)
{
_input = new AccountCategories();
_input.CreatedBy = "super-admin";
_input.CreatedTime = DateTime.Now;
_input.Id = new ObjectId();
_input.IsActive = true;
_input.Name = "test-name";
var _result = _repo.Insert(_input);
return _result;
}
- 插入的数据:{4/30/16 9:04:36 PM}
- 检索数据:{4/30/16 2:04:36 PM}
我曾尝试通过添加 Bson 属性来修改实体,但它不起作用:
[BsonRepresentation(BsonType.Document)]
public DateTime CreatedTime { get; set; }
为什么会发生这种行为?我该如何解决这个问题?
【问题讨论】: