This project has moved. For the latest updates, please go here.

Id not passed correctly for classes that inherit from IEntity

Aug 2, 2012 at 7:27 PM

When model classes inherit from Entity, everything seems to work ok, but we had a problem with serialization (only the Id was serialized). So we now inherit from IEntity and add our own Id property as follows

        [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]
        public string Id { get; set; }

At that point the id is not recognized correctly

            string id = "actualId";
              // GetSingle will return the class
            var sample = _db.GetSingle(c => c.Id == id);

              // GetById will return null (Delete will do nothing)
            var model = _db.GetById(id);

Any ideas?

Aug 2, 2012 at 7:30 PM

By the way, I tried adding

[BsonId]

to the Id property without any noted effect.

Coordinator
Aug 11, 2012 at 8:36 PM

Hi,

Sorry for the late reply, I was on holiday. I will look into your question soon (hopefully this week sometime).

Aug 16, 2012 at 11:41 PM

Thank you!

Coordinator
Aug 17, 2012 at 12:17 AM

This seems to be similar (and/or related) to this post. Could you elaborate a bit more on "we had a problem with serialization" like: what kind of serialization (JSON? XML? Other?) and what kind of product (or BCL class) used for the serialization? Also; the post I referred to might point you in the right direction. If not, please let me know.

Aug 17, 2012 at 1:03 AM

The referenced post solves the issue with Entity, so we will avoid this one by switching back to using the Entity class.