[CSHARP-612] Generic query builder throws exception when Injected using LINQ Created: 24/Oct/12  Updated: 20/Mar/14  Resolved: 04/Nov/12

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 1.6
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Zaid Masud Assignee: Craig Wilson
Resolution: Won't Fix Votes: 0
Labels: linq
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

public class Document
{
    public ObjectId Id { get; set; }
}
 
[Test]
public void InjectGenericQueryBuilder()
{
    var doc = _collection.AsQueryable<Document>().SingleOrDefault(x => Query<Document>.EQ(y => y.Id, ObjectId.Empty).Inject());
}

The following exception is thrown when this unit test is run:

System.ArgumentException : Unsupported where clause: LinqToMongo.Inject...

This is true for pretty much any Inject done using generic query builder.

Note that the non-generic query builder (where field name is specified as magic string) works fine.



 Comments   
Comment by Zaid Masud [ 06/Nov/12 ]

Thanks for demonstrating the workaround, I suppose the important thing is that it's documented here so it could be of help to others. A Google search on "generic inject exception C# mongodb" shows this ticket as the first result so hopefully others will find it useful!

Comment by Craig Wilson [ 04/Nov/12 ]

We have decided not to fix this. Other than it getting really tricky, there is a simple workaround and embedding this type of thing in the query doesn't make a lot of sense.

A majority of the typed query builder's functions can be done natively with Linq. For those few operations that can't, then they can always be expressed prior to the query and injected in. As self-document comparisons aren't allowed (doc.A == doc.B), then there is no need to have a reference to anything else in the query.

[Test]
public void InjectGenericQueryBuilder()
{
    var query = Query<Document>.EQ(y => y.Id, ObjectId.Empty);
    var doc = _collection.AsQueryable<Document>().SingleOrDefault(x => query.Inject());
}

If you have a compelling reason this is necessary, please feel free to comment and we can revisit the issue.

Comment by Craig Wilson [ 04/Nov/12 ]

In code review...

Generated at Wed Feb 07 21:37:20 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.