CSharp Driver: Problem querying Guid Id represented as String in subclass

77 views
Skip to first unread message

Christian Sparre

unread,
Oct 4, 2012, 7:02:21 AM10/4/12
to mongod...@googlegroups.com
I have a base class Element and a subclass Survey

In simple form they look like this :)

Element 
{
  Guid Id;
}

Survey : Element
{
  String Title;
}

The Guid Id is represented as a string in the database using the [BsonRepresentation(BsonType.String)] attribute

When I save documents and return them all (FindAll) everything works fine and they are serialized and deserialized as expected.

But when I try to do the following it fails with the error "Unable to determine the serialization information for the expression: f.Id"

Collection<Survey>.AsQueryalble().Where(f=>f.Id == id)

But if I query only on the base class Element

Collection<Element>.AsQueryalble().Where(f=>f.Id == id) it works as expected.

I have no class maps created manually, and when I lookup the Survey class map the Id property seems to be mapped correctly with the string representation

Any idea?, I know there was a problem with inherited properties and querying, but that was a long time ago. Also before I changed the representation to string I had no problems.

-- 
Christian

craiggwilson

unread,
Oct 4, 2012, 9:46:15 AM10/4/12
to mongod...@googlegroups.com
You need to access the collection using the base class and then us OfType to add the type restriction.

Colleciton<Element>.AsQueryable().OfType<Survey>().Where(f => f.Id == id);

craiggwilson

unread,
Oct 4, 2012, 11:36:26 AM10/4/12
to mongod...@googlegroups.com
Was just talking about this with Robert and I may have misunderstood your question.  You may have hit this bug (which has been fixed for a little while): https://jira.mongodb.org/browse/CSHARP-418.  What version of the driver are using?

Christian Sparre

unread,
Oct 5, 2012, 3:55:30 AM10/5/12
to mongod...@googlegroups.com
I'm using version 1.6 installed via nuget.

I just made a test with Id's stored the default way (BinData(3.....)) and it works fine when querying with Linq

/Christian

craiggwilson

unread,
Oct 5, 2012, 11:36:32 AM10/5/12
to mongod...@googlegroups.com
That definitely sounds like a bug.  Could you file a ticket at jira.mongodb.org with your sample code so we can reproduce?  Thanks...
Reply all
Reply to author
Forward
0 new messages