MongoDB Unable to determine the serialization information
NickName:user3664916 Ask DateTime:2014-10-06T20:24:42

MongoDB Unable to determine the serialization information

I'm having a problem with Mongodb querying. Here's the classes:

    class A
    { 

    }
    class B : A
    { 

    }
    class C : A
    {
        public string prop1 { get; set; }
    }
    class D
    {
        public List<A> collection1 { get; set; }
    }

And the query:

   var query1 = Query<D>.ElemMatch(d => d.collection1.OfType<C>(), 
             builder => builder.EQ(c => c.prop1, "val1"));

In a nutshell I want to select all instances of class D whose collection "collection1" contains at least one instance of class C whose property "prop1" equals "val1".

This keeps throwing "Unable to determine the serialization information for the expression" out of the blue.

What am I doing wrong? I've tried decorating "A" with BsonKnownTypes(typeof(B), typeof(C)) to no avail.

PS: if I had only one class A:

    class A
    { 
        public string prop1 { get; set; }
    }
    class D
    {
        public List<A> collection1 { get; set; }
    }

then this code works and does exactly what I want:

   var query1 = Query<D>.ElemMatch(d => d.collection1, 
             builder => builder.EQ(c => c.prop1, "val1"));

but it's not what I want, I want to keep "B" and "C" that inherit from "A".

Copyright Notice:Content Author:「user3664916」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/26216185/mongodb-unable-to-determine-the-serialization-information

More about “MongoDB Unable to determine the serialization information” related questions

MongoDB Unable to determine the serialization information

I'm having a problem with Mongodb querying. Here's the classes: class A { } class B : A { } class C : A { public string prop1 { get; set; }

Show Detail

Unable to determine the serialization information for

While trying to Upsert a list @ MongoDB i get the following error: &quot;Unable to determine the serialization information for o =&gt; o.&quot; Order.cs *(removed properties for testing): public ...

Show Detail

Unable to determine the serialization information for "Expression"

I receive the error message Unable to determine the serialization information for a => a.CurrentProcessingStep when I try to Update my document. I'm using the Mongo .NET Driver version 2.8 and .NET

Show Detail

MongoDB Unable to determine the serialization information for the expression error

My data is having following structure public enum ParamType { Integer=1, String=2, Boolean=3, Double=4 } public class Gateway { public int _id { get; set; } public string

Show Detail

Unable to determine the serialization information when trying to query the child MongoDB C#

Um sharing my code Im using to query and get a matching child element to do an update to an element in an array in mongoDB Collection var filter = Builders&lt;Fruit&gt;.Filter.Eq...

Show Detail

Unable to determine the serialization information for *expression* using .Date

I'm trying to read from a mongoDB collection with a Date filter (only the Date, time should be ignored): var filterDefinition = Builders&lt;SomeClass&gt;.Filter.Eq(p =&gt; p.SomeDateTimeProperty.D...

Show Detail

MongoDb - Unable to determine the serialization information

I want to update a property that exists on a class that inherits from the ISettingWidgets interface. When I run the code below, I get the error: System.InvalidOperationException: Unable to determin...

Show Detail

Unable to determine the serialization information IIF

I have a price range query I'm trying to write for my C# code and depending on the currency type of the product I need to query the correct field var minPrice = builder.Gte(s =&gt; s.Price.Currenc...

Show Detail

Unable to determine the serialization information for the expression error

I'm getting an Unable to determine the serialization information for the expression: (PlaceManager pm) =&gt; pm.FreePlaces.get_Item(index) error when trying to remove value from database (Mongo DB)...

Show Detail

Unable to determine the serialization information for the expression for simple equals operator in MongoDB

I'm currently having an issue where I can't use an Expression&lt;Func&lt;TDocument, bool&gt;&gt; predicate for a simple i =&gt; i.UserName == username query. I have the following model class: pub...

Show Detail