Reputation: 11247
My goal is to initialize a class that represent a document (Book) that has a containing document (Details). Developing in ASP.NET / C# / MongoDB.
I have the following C# class:
Public Class Book{
public BsonString Name {get; set;}
}
How do I add an embedded document to that class.
For example:
I want the details
to be included as a sub collection (embedded document) inside the parent document when I insert it to MongoDB database.
Upvotes: 0
Views: 1004
Reputation: 116548
There you go:
public class Book
{
public string Name {get; set;}
public Details Details {get; set;}
}
public class Details
{
public DateTime PublishDate {get; set;}
public string Author {get; set;}
}
Upvotes: 3