Re: C# 2.0: Deserializing with convention pack

25 views
Skip to first unread message
Message has been deleted

Craig Wilson

unread,
May 21, 2015, 7:16:50 PM5/21/15
to mongod...@googlegroups.com
Hi Philip,

Sorry you are having trouble. To make a diagnosis, I'd need to see a more complete program. For instance, you are calling Find<T>... what is T? And what type is the collection? 

Regarding filter, you can use a BsonDocument as a filter, but it will not get mapping information applied to it. However, you can use the FilterDefinitionBuilder (Builders<Student>.Filter)  and use strings with it and it will get the mapping information applied.

Craig

On Thursday, May 21, 2015 at 5:20:58 PM UTC-5, Philip Bergström wrote:
Hi,

I am storing objects in my MongoDb, using a CamelCase pack. For example, an object like:


        public class Student : MongoObject
        {
            public string Name { get; set; }
            public int Year { get; set; }
        }

is stored like:

{
  "year : 2000",
  "name" : "Philip"
}

Now I want to deserialize the document into a Student object:

var filter = new BsonDocument();
var foundEnt = await collection.Find<T>(filter).FirstOrDefaultAsync();

However, the driver doesn't seem to understand the mapping, and it returns a Student object with null fields. 
Deserialization works fine when using the lambda format (which means that the camelcase is correctly registered), however, I need to use the BsonDocument-filter type for my current work.

Is this a bug or I am doing something wrong?

 



Philip Bergström

unread,
May 22, 2015, 3:41:11 AM5/22/15
to mongod...@googlegroups.com
I see, sorry for insufficient data. I will simply use the FilterDefinitionBuilder to apply the mapping then.

Thanks!
Reply all
Reply to author
Forward
0 new messages