I have the following class hierarchy
public class Beneficiary
{
public string Id { get; set; }
public string Name { get; set; }
public InvoiceNumber InvoiceNumber { get; set; }
public ICollection<Invoice> Invoices { get; set; }
}
public class InvoiceNumber
{
public string Current { get; set; }
public DateTime IssueDate { get; }
}
public class Invoice
{
public string Number { get; set; }
public DateTime IssueDate { get; }
public ICollection<InvoiceEntry> InvoiceEntries { get; set; }
}
public class InvoiceEntry
{
public decimal BillableHours { get; set; }
}
Up till now I've used EF to configure relations but I would like to move to mongo (this is just for learning purposes). In entity frameowrk I know how to map this type of hierarchy, but i don't know in mongo.
As it is seen only Beneficiary has an Id attached and generated but the rest is just a dependent hierarchy, so if the beneficiary gets deleted everything else will get deleted.
Can I map such class structure in mongo ? I'm using fluent api for mapping
BsonClassMap.RegisterClassMap<Beneficiary>(type =>
{
type.MapIdProperty(prop => prop.Id)
.SetIdGenerator(new StringObjectIdGenerator())
.SetSerializer(new StringSerializer(BsonType.ObjectId));
type.MapProperty(prop => prop.Name)
.SetIsRequired(true);
});
but I'm stuck because I don't know how to continue mapping the complex data types.