NoRM icon indicating copy to clipboard operation
NoRM copied to clipboard

Cannot use IQueryable.Where with class Id property

Open rushidesai opened this issue 14 years ago • 3 comments

If I have a document class with a composite Id (i.e. using a custom class) and I access the Id property in the IQueryable.Where method for the associated collection, the property is not aliased correctly. Example:

class CustomerId { public string Type { get; set; } public int SeqNum { get; set; } }

class Customer { public CustomerId Id { get; set;} public string Name { get; set;} }

var x = database.GetCollection<Customer>().AsQueryable().Where(c => c.Id.Type == "Premium");

rushidesai avatar Jul 31 '10 18:07 rushidesai

Since this seems to be an edge-case, we will work to resolve this in a post-1.0 release.

atheken avatar Aug 04 '10 01:08 atheken

Since this seems to be an edge-case, we will work to resolve this in a post-1.0 release.

atheken avatar Aug 04 '10 01:08 atheken

I seem to be running into this with implicit composite Id's, i.e. those created as a result of DbRefererence<Foo, string> as well.

A query like this:

db.GetCollection<Bar>.AsQueryAble().Single(b = > b.ParentItem.Id == "someString")

results in an InvalidOperationException: Sequence contains no elements. Bar is defined thus: class Bar { public DbReference<Foo, string> ParentItem; // some other properties of Bar }

and Foo is defined thus: class Foo { [MongoIdentifier] public string Id; // some other properties }

I think this is happening because NoRM is sending the following query to MongoDb:

db.Bar.find( { ParentItem._id : "someString" } )

This doesn't work for me (and returns 0 rows) when I run it using the Mongo command-line client. Instead, the following query works:

db.Bar.find( { "ParentItem.$id" : "someString" } )

I see code in MongoConfigurationMap.IsDbReference which is supposed to override the Id -> _id mapping, but for whatever reason it does not get triggered.

Ideas?

pacificsky avatar Feb 26 '11 05:02 pacificsky