[CSHARP-1755] LINQ support with Custom Serializer Created: 26/Aug/16  Updated: 09/Nov/22  Resolved: 09/Nov/22

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

Type: New Feature Priority: Major - P3
Reporter: Emiliano Conti Assignee: James Kovacs
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 7 Enterprise SP1



 Description   

I have a pair of classes like:

class Parent{
 string Id {get;set;}
 Children children {get;set;}
}
 
class Children{
 string Id {get;set;}
}

An example of these classes serialized would be:

// Parent
{
 "_id":ObjectId("1"),
 "children":ObjectId("2")
}
 
// Children
{
 "_id":ObjectId("2")
}

I would like to be able to filter a collection of the class Parent by using the Children Id property like this:

GetCollection<Parent>("Parent").AsQueryable().Where(x => x.Children.Id == "2")

is this possible? If not, is there a workaround to this?



 Comments   
Comment by James Kovacs [ 09/Nov/22 ]

Both LINQ2 and LINQ3 allow querying by properties on nested classes. If something isn't working as expected, please re-open this ticket or file a new one.

Comment by Craig Wilson [ 28/Sep/16 ]

Hi Emilliano,

I'm not sure if that;s possible, although I think it probably is not. There are 2 interfaces that can be implemented on classes/collections that help LINQ out. If it can't be done using those interfaces, we'll have to introduce other ones that aren't currently there. IBsonDocumentSerializer and IBsonArraySerializer.

Craig

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