[CSHARP-2466] InvalidOperationException with IQueryable and ExtraElements Created: 28/Dec/18 Updated: 25/Jun/20 Resolved: 25/Jun/20 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | BSON, Linq |
| Affects Version/s: | 2.7.2 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Vincent Ugenti | Assignee: | Wan Bachtiar |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
Trying to integrate Microsoft OData v4 stack with Mongo C# Driver. I would like to expose a Mongo collection and enable the OData $filter operation against the fields contained in the ExtraElements dictionary. I have created a minimal example of the issue. Beginning with an empty WebAPI project in Visual Studio 2015, I created the following model: public class TestEntity { [BsonId, BsonElement("_id")] public ObjectId _id \{ get; set; }public string Id { get; set; } [BsonExtraElements] I exposed EDM EntitySet via OData by adding the following at the end of `WebApiConfig.Register()` method: // OData config.MapODataServiceRoute("odata", "odata", edmBuilder.GetEdmModel()); Finally, I created a simple TestController: public class TestController : ODataController } I added an actual object to the Mongo collection: > db.test.insert( {Id:'test', Name:'testName'}) WriteResult({ "nInserted" : 1 }) > { "_id" : ObjectId("5c266040fd7e5a3c63b33cd8"), "Id" : "test", "Name" : "testName" } Now I can query find as long as I don't try to use $filter on the ExtraElements (note that OData is not rendering the ObjectId field properly, but I do not believe this is related to the problem): http://localhost:63927/odata/test {"@odata.context":"http://localhost:63927/odata/$metadata#test","value":[\{"Id":"test","Name":"testName","_id":{}}]} However, if I try to filter against the `Name` (one of the `ExtraElements`) the following error occurs: http://localhost:63927/odata/test?$filter=Name%20eq%20%27testName%27 *Message: Convert(IIF((({document} {ExtraElements} != null) AndAlso {document}{ExtraElements}.ContainsKey(\"Name\")), {document} {ExtraElements}.Item[\"Name\"], null)) is not supported.* Exception: System.InvalidOperationException Stack Trace:
|
| Comments |
| Comment by Rachelle Palmer [ 25/Jun/20 ] |
|
Hi there, thank you for reaching out to MongoDB. As this sounds more like a support issue, I wanted to give you some resources to get this question answered more quickly:
Thank you! |
| Comment by Vincent Ugenti [ 28/Dec/18 ] |
|
Also to clarify further, if the "Name" property is then added to the TestEntity class, the $filter operation works as expected. |