alexandre-spieser / mongodb-generic-repository

An example of generic repository implementation using the MongoDB C# Sharp 2.0 driver (async)
MIT License
315 stars 87 forks source link

Question: Nested Documents #11

Closed vella-nicholas closed 5 years ago

vella-nicholas commented 5 years ago

When you have nested documents, should both classes implement IDocument? Do you need to set the BsonId for the ID property of the nested object?

alexandre-spieser commented 5 years ago

Hi, only the main document class should implement IDocument, not the nested objects. For the nested entities you must generate the Ids yourself, the mongodb driver does not seem to populate them by default.

vella-nicholas commented 5 years ago

Thank you for your answer, Alexandre.

alexandre-spieser commented 5 years ago

No problem.