[CSHARP-611] Support for Enumerable.Any in LINQ queries for StringSerializer like List<string> Properties Created: 23/Oct/12  Updated: 27/May/22  Resolved: 24/Apr/15

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

Type: Improvement Priority: Minor - P4
Reporter: Huseyin Yurtseven Assignee: Craig Wilson
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File Capture.PNG    
Issue Links:
Depends
depends on SERVER-1264 $elemMatch on subArray Closed
depends on SERVER-5506 Enhance SERVER-1264 style $elemMatch ... Backlog
Epic Link: Rewrite Linq
Server Compat: 2.6
Backwards Compatibility: Major Change

 Description   

In OData Any Queries for IList<string> properties like ?$filter=Links/any(x: x eq '/movies/') don't work and it gives "Any is only support for items that serialize into documents. The current serializer is StringSerializer and must implement IBsonDocumentSerializer for participation in Any queries." error.

That would be good to add support like these queries or x=>x.Links.Any(l=>l.StartsWith("/mov"))



 Comments   
Comment by Craig Wilson [ 24/Apr/15 ]

This was fixed with CSHARP-601.

Comment by Craig Wilson [ 23/Oct/12 ]

If you see when we implemented this in CSHARP-413, we attempted to get this in. However, it appears as though the server does not support arrays of primitives for $elemMatch, and therefore, we don't either. I've attached some links to server tickets that indicate this isn't yet fully supported.

Comment by Huseyin Yurtseven [ 23/Oct/12 ]

Hi,

Thanks for you quick reply.

1) We use latest 1.6 version as Driver

2) We use System.Web.Http.OData as Odata Provider and ASP.NET MVC Web Api with Queryable attribute

[Queryable(EnsureStableOrdering = false, HandleNullPropagation = HandleNullPropagationOption.False, ResultLimit = 100)]
public IQueryable<Content> Get()

3) Sample class hierarchy (by the way i tried without inheritance with plan class)

Base [_id, Title, Description etc.]
Content [Links(IList<string>, Tags (IList<string>)), etc.] : Base
Media [SpriteImages(IList<MediaFile>), etc.]: Content

4) I attached a screenshot and i'm writing a sample linq query.

Here is the query:

var collection = _context.GetDatabase().GetCollection("Contents").AsQueryable<Content>();

var list = collection.Where(x => x.Links.Any(l => l.StartsWith("/diziler/")));
foreach (var li in list)

{ Response.Write(li.Title + "<br/>"); }

And you can look attached file.

Thanks

Comment by Huseyin Yurtseven [ 23/Oct/12 ]

Error screen

Comment by Craig Wilson [ 23/Oct/12 ]

First of all, what OData library are you using? We don't have any odata libraries, so I can only assume you are using the ReflectionProvider. There are a number of issues with using the ReflectionProvider with our linq implementation simply because OData requires some very specific things.

So, if you could provide some more information:

1) What version of the driver are you using?
2) What OData provider are you using?
3) What does your class hierarchy look like?
4) Can you reproduce this without OData (for instance, just using the driver natively with this type of query?)

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