I've the following mongodb document schema;
{
"_id" : ObjectId("5c9d34ff781318afb9e8ab43"),
"name" : "Name",
"slug" : "slug",
"services" : {
"subservice" : {
"id" : NumberInt(37030)
}
}
}
and then i define my classes as;
public class MainModel
{
public ObjectId Id { get; set; }
[BsonElement("name")]
public string Name { get; set; }
[BsonElement("slug")]
public string Slug { get; set; }
[BsonElement("services")]
public ServicesDef Services { get; set; }
public class ServicesDef
{
[BsonElement("subservice")]
public SubServiceDef SubService{ get; set; }
public class SubServiceDef
{
[BsonElement("id")]
public int Id { get; set; }
}
}
}
But somehow when I query the document;
var result = await Repository.FindAsync(x => x.Slug == slug);
That services.subservice.id isn't properly registered and getting
Element 'id' does not match any field or property of class SubServiceDef.
Stuck here and looking for advice.
I think I'm having the same issue with cannot deserialize with the "Id" attribute but seems there is solution yet.