[CSHARP-1714] Cannot translate simple expression. InvalidOperationException in Linq.Translators.PredicateTranslator: {document} not supported. Created: 20/Jul/16  Updated: 31/Oct/17  Resolved: 20/Jul/16

Status: Closed
Project: C# Driver
Component/s: API, Linq
Affects Version/s: 2.2.4
Fix Version/s: None

Type: Bug Priority: Critical - P2
Reporter: Ioan Crisan Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 10 x64, IIS.



 Description   

The exception occurs in the method GetFieldExpression, for the following expression:
e => ((e.GetType() == BusinessPartner) AndAlso (e.PrivateExchangeId == "something"))

The code triggering the exception is:

var documentSerializer = BsonSerializer.SerializerRegistry.GetSerializer<T>();
var renderedFilter = filterDefinition.Render(documentSerializer, BsonSerializer.SerializerRegistry).ToString(); // the exception occurs in Render

The filter definition is of type MongoDB.Driver.AndFilterDefinition<BusinessPartner>, and has as expression the expression provided above.



 Comments   
Comment by Svetoslav Milenov [ 31/Oct/17 ]

@Lewis Gill ... As I was not able to reopen the issue, I cloned it to CSHARP-2080

I also have put my workaround there.

Comment by Lewis Gill [ 04/May/17 ]

I'm running into the same error here, but I have a set of Type variables that I'm using to build up a dynamic LINQ query, so I can't use the "is" clause.

Is there a way to make the following work?

Type type = typeof(string);

query.Where( c => c.GetType() == type);

Comment by Ioan Crisan [ 20/Jul/16 ]

I suppose you can close this issue now. Thanks again!

Comment by Ioan Crisan [ 20/Jul/16 ]

It works with the is operator, thanks!

Comment by Ioan Crisan [ 20/Jul/16 ]

Hi Craig,

it is accurate, because due to this error we cannot update the driver to this version to be able to get a more detailed log. We have some strange latencies that we observed in the production environment, which we could reproduce locally, but without this newer driver we cannot investigate further (see CS-27499 for that matter - we managed to reproduce the situation when the driver needs 6 seconds for retrieving 350 entities, while the database logs indicate milliseconds).

I will check to see if I can change the expression as indicated.

Thanks for the update,
Ioan

Comment by Craig Wilson [ 20/Jul/16 ]

Hi Ioan,

I see you've marked this as critical. Is that accurate? The exception in this code is getting generated by the e.GetType() == BusinessPartner. Could you try using

(e is BusinessPartner)

instead. I believe I see some support for that variation in the code.

Craig

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