【发布时间】:2018-11-15 12:28:32
【问题描述】:
我正在使用 MongoDB 驱动程序在我的 C# .NET Core 应用程序中使用 Azure CosmosDB 的 Mongo API。
我有一个包含以下内容的课程:
class MyModel
{
[BsonElement("mydate")]
public string MyDate { get; set; }
}
当我尝试检索模型时(表包含DateTime),我收到以下错误:
无法从 BsonType 'DateTime' 反序列化 'String'。
我试过这样做:
[BsonElement("mydate")]
[BsonRepresentation(BsonType.DateTime)]
public string MyDate { get; set; }
但后来我得到了这个错误:
DateTime 不是 StringSerializer 的有效表示。
【问题讨论】: