[CSHARP-761] Allow LINQ lambda expressions to be used for queries in .Remove and .Update operations Created: 14/Jun/13  Updated: 20/Mar/14  Resolved: 14/Jun/13

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

Type: Improvement Priority: Minor - P4
Reporter: Einar Egilsson Assignee: Unassigned
Resolution: Done Votes: 0
Labels: linq, remove, update
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

The Query and Query<T> API's that we have to use for Update and Remove operations are pretty verbose and annoying to work with. It would be great to be able to use lambda expressions instead.

E.g. instead of

coll.Update(Query.Or(Query.EQ("Id", "..."), Query.EQ("Name", "John")), update)

we could do

coll.Update(o => o.Id == "..." || o.Name == "John", update)

Same for Remove.

Pull request is on it's way...



 Comments   
Comment by Craig Wilson [ 14/Jun/13 ]

An extension method is easy enough to write, so if you would like something like this, feel free to write one. We are currently going through a bit of a redesign of the CRUD syntax for all the drivers and so we'll definitely keep this in mind during that discussion...

Thanks for your input!!!

Comment by Einar Egilsson [ 14/Jun/13 ]

Totally missed that! OK then, just close this issue. Although I still think it would be nice to have an extension method that took the lambda expression in directly.

Comment by Robert Stam [ 14/Jun/13 ]

This is already possible. You can do it like this:

collection.Update(Query<T>.Where(o => predicate(o)), update);

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