I'm trying to work on an app that has two main domain entities: Entry and Category, and I'm going to use mongodb. I will have one collection for Entries and one for Categories. Entries collection may have thousands of hundreds of documents, and Categories hundreds.
In my view, I want to show all entries' information and their category name and color. I'd like to keep their category id so I can update the affected entries if a category name or color changes. So I'd like to have a document like that:
{
"_id": 123456,
"date": '2018-08-15',
"description": "Some entry description"
....
category:
{
"id": 123,
"name": "My category",
"color:" "blue"
}
The problem is that Category has lots more of properties, so my document ends up like that:
{
"_id": 123456,
"date": '2018-08-15',
"description": "Some entry description"
....
category:
{
"id": 123,
"name": "My category",
"color": "blue",
"otherProp": "a",
"anotherProp": "b",
"differentProp": "c"
}
}
I tried to use BsonClassMap.RegisterClassMap to map only some properties of Category for Entry collection but that seems not possible. If I ignore some Category property, categories` collection will not have these ignored items as well.
Should I work on a different model representation like bellow or create new entities to save the information as I want (so my repository won't persist Entry but will persistEntryDataObject)?
public class Entry {
public string Description { get; set; }
...
public Category Category { get; set; }
}
public class Category {
public string Name { get; set; }
public string Color { get; set; }
}
public class CategoryExtraInformation {
public string OtherProp { get; set; }
public string AnotherProp { get; set; }
public string DifferentProp { get; set; }
public Category Category { get; set; }
}
[Ignore]and ignoring extra properties. api.mongodb.com/csharp/1.5/html/…