[CSHARP-4058] LinqV3 Expression Not Supported: True Created: 16/Feb/22  Updated: 27/Oct/23  Resolved: 16/Mar/22

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

Type: Bug Priority: Unknown
Reporter: Rich Collette Assignee: Boris Dogadov
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Epic Link: CSHARP-3615

 Description   

Summary

When assigning a true literal/primative

.Project(
    augmentedProductType => new ProductTypeSearchResult
    {
        isSomething = true 
    }
)

 
And InvalidOperationException results with the message "Expression not supported: True"

This also occurs when using a where clause in nested select within the project (although the case may be more general than that)

 .Project(
    augmentedProductType => new ProductTypeSearchResult
    {
        Description = augmentedProductType.ExternalProductTypeDescription,
        ProductTypeId = augmentedProductType.ProductTypeId,
        Name = augmentedProductType.Name,
        ProductFamilyId = augmentedProductType.ProductFamilyId,
        Url = augmentedProductType.ShopUrl ?? augmentedProductType.TypeUrl,
        Score = augmentedProductType.Score,
        Products = augmentedProductType.Products
            .Select(
                productForSelect => new ProductSearchResult
                {
                    ProductId = productForSelect.ProductId,
                    ProductInfo = productForSelect.ProductInfo,
                    Deliveries = augmentedProductType
                        .Deliveries 
                        .Where(
                            deliveryForWhere =>
                                deliveryForWhere.ProductId ==
                                productForSelect
                                    .ProductId)
                        .Select(
                            deliveryForSelect =>
                                new DeliverySearchResult
                                {
                                    DeliveryId = deliveryForSelect.DeliveryId,
                                    Language = deliveryForSelect.Language,
                                    Platform = deliveryForSelect.Platform,
                                    OperatingSystem = deliveryForSelect.OperatingSystem,
                                    ReleaseInfo = deliveryForSelect.ReleaseInfo
                                })
                })
            // THIS WHERE CLAUSE CAUSES THE ERROR
            .Where(
                productSearchResult => productSearchResult.Deliveries != null )

Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

Driver version 2.4.1

How to Reproduce

Steps to reproduce. If possible, please include a Short, Self Contained, Correct (Compilable), Example.

Additional Background

Please provide any additional background information that may be helpful in diagnosing the bug.

Stack

MongoDB.Driver.Linq.ExpressionNotSupportedException: Expression not supported: True.
   at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToFilterTranslators.ToFilterFieldTranslators.ExpressionToFilterFieldTranslator.Translate(TranslationContext context, Expression expression)
   at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToFilterTranslators.ExpressionToFilterTranslator.TranslateUsingQueryOperators(TranslationContext context, Expression expression) 

 



 Comments   
Comment by PM Bot [ 16/Mar/22 ]

There hasn't been any recent activity on this ticket, so we're resolving it. Thanks for reaching out! Please feel free to comment on this if you're able to provide more information.

Comment by Richard Collette [ 01/Mar/22 ]

@Boris Dogadov - I am going to have difficulty finding the time to assemble a self contained demo of the second issue.  We can close this ticket and if necessary I'll create a new one if  if it continues to be an issue for me once https://jira.mongodb.org/browse/CSHARP-4062 is resolved.

Thank you for following up on it.

Comment by Boris Dogadov [ 16/Feb/22 ]

Hi richard.collette@precisely.com,

Thank you for reporting this behaviour, we have filed a ticket for the first issue:
https://jira.mongodb.org/browse/CSHARP-4062
But please note that this expression works when adding a reference to the input object :

 

.Project(
  augmentedProductType => new ProductTypeSearchResult
  {
     isSomething = true,
     isSomethingElse = augmentedProductType...
  }
)

We could not reproduce the second issue on 2.14.1 driver with LINQ3.
Could you please provide a full self-contained sample that reproduces the problem for this case as well?

 

The following sample works as expected:

 

var clientSettings = MongoClientSettings.FromConnectionString(@"mongodb://localhost:27017");
clientSettings.LinqProvider = LinqProvider.V3;
var client = new MongoClient(clientSettings);
var database = client.GetDatabase("samples");
var collection = database.GetCollection<NestedContainer>("nested");
var movies = collection.
  Aggregate().
  Project(s => new Movie2
  {
     BoolField = true,
     Summaries = s.Movies.Select(m => new Summary() { StrField = m.title } ).Where(m => m.StrField != null).ToArray()
  }).
  ToList();

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