1

I am new to MongoDb but have an existing application which would benefit heavily from using it to store encapsulated data for fast retrieval and updating.

Now the problem I have is that I have existing models which are just simple POCOs without any framework specific attributes or dependencies, they do however have an Id field which is an int (some differ but its easier to just assume all are ints in this instance). Now without tying that object to MongoDb (be it attribute round the id field or changing their types to ObjectId fields) is there any way for it to automagically pick up the id field through external config?

If not its not the end of the world I will just make a domain object that is mapped to and from for MongoDb purposes like I have with Nhibernate. I would just rather not have to have 2 versions of the same classes just differing with the Id field. As in this case the domains will be identical.

Grofit
  • 17,693
  • 24
  • 96
  • 176

1 Answers1

0

The C# driver's support for serialization is described here:

http://www.mongodb.org/display/DOCS/CSharp+Driver+Serialization+Tutorial

A principal of the serialization support is that while annotating your domain objects with attributes is by far the easiest way to control serialization, anything you can do with attributes can also be done without them for those developers who want to keep their domain model persistence ignorant and free of dependencies on MongoDB.

Look for examples using RegisterClassMap in the tutorial.

Robert Stam
  • 12,039
  • 2
  • 39
  • 36