I am writing a Mongo web application using their official C # driver.
To implement links, they must be loaded manually.
so let's say that
class User {
...
public MongoDBRef Topic { get; set; }
}
To get the topic, we need to do the following:
db.FetchDBRefAs<Topic>(user.Topic);
And to create a new one:
user.Topic = new MongoDBRef(TopicsTable, topic._id);
I decided to create a virtual property to make it more convenient:
[BsonIgnore]
public Topic _Topic
{
get
{
return db.FetchDBRefAs<Topic>(Topic);
}
set
{
CreatedAd = new MongoDBRef(TopicsTable, value._id);
}
}
Now I can use it as follows:
user._Topic = someTopic;
anotherTopic = user._Topic;
Obviously, this is a big pain to do this for all referenced objects.
Is there a way to make this process automatic?
thank
source
share