简而言之:默认Console Application项目中的方法工作正常,但在另一个项目(asp.net WebAPI)中相同的方法不起作用。我有两个 mongoDB 集合,如下所示。主题集合的示例文档(JSON):
{
"_id" : ObjectId("5b9a2637635d16b2a2c5c562"),
"userId" : ObjectId("5b9a23d1a54d26b98f6acf34"),
"name" : "someName",
"notes" : [
{
"date" : ISODate("2012-11-20T05:05:15.229Z"),
"title" : "someTitle",
"body" : "Note body - long teeeeeeext",
"files" : [ ]
}
]
}
用户集合示例文档:
{
"_id" : ObjectId("5b9a23d1a54d26b98f6acf34"),
"loginName" : "someName",
"pass" : "hashedpassword"
}
我写了几个类(POCO Representation):
public class Subject
{
[BsonElement("_id")]
public ObjectId Id { get; set; }
[BsonElement("name")]
public string Name { get; set; }
[BsonElement("notes")]
public List<Notes> Notes { get; set; }
[BsonElement("userId")]
public ObjectId UserId { get; set; }
}
public class Notes
{
[BsonElement("date")]
[BsonRepresentation(BsonType.DateTime)]
public DateTime Date { get; set; }
[BsonElement("title")]
public string Title { get; set; }
[BsonElement("body")]
public string Body { get; set; }
[BsonElement("files")]
public List<ObjectId> Files { get; set; }
}
public class User
{
[BsonElement("_id")]
public ObjectId Id { get; set; }
[BsonElement("loginName")]
public string LoginName { get; set; }
[BsonElement("pass")]
public string HashedPass { get; set; }
}
婷婷同学_
相关分类