20
I have a class User and I need to work with them in web services.
Then problem is that if I try to serialize Id that is type of BsonObjectId, I see
that have an empty property, that have an empty property, and so on ...
I have write this workaround in order, it's is a good solution?
public partial class i_User
{
[BsonId(IdGenerator = typeof(BsonObjectIdGenerator))]
[NonSerialized]
public BsonObjectId _id;
public String Id
{
get
{
return this._id.ToString();
}
}
}
In this way, I can keep _Id as BsonObjectId but I send an string representation over the web in the property Id.
Another solution is to work with StringObjectIdGenerator
public partial class i_User
{
[BsonId(IdGenerator = typeof(StringObjectIdGenerator))]
public String id;
}
But is see that MongoDB will store a string into database instead of ObjectId.
What is the best approach in order to work in a serialization environmental like web services and/or an client-server (Flash+C#)?