Closed gyf19 closed 10 years ago
I think it might be done with returning a MongoQueryable
What do you think ? Is it acceptable to hijack the AsQueryable method for doing that ? Or maybe a Fluent() extension method ?
I think what he is looking for is a way to do this:
Collection.Update(x => x.LastName == "Jackson", new { FirstName = "Jim" })
UPDATE Collection SET FirstName = 'Jim' WHERE LastName = 'Jackson'
Effectively, take an Expression in the first parameter and let linq convert it into a document...
Yep, that's what I meant.
But how do you want to modify the Update method in the mongodb collection ? That's why I propose using a custom collection class when using the AsQueryable().
MongoCollection.AsQueryable().Update(x => x.LastName == "Jackson", new { FirstName = "Jim"})
As this method will reuse a lot of fluent-mongo code, I think it's good to have it in fluent-mongo instead of reimplementing it in mongodb csharp driver. I ran into this issue recently (and with Delete as well) and might give it a quick look.
Checkout the code at https://github.com/mongodb-csharp/mongodb-csharp/blob/master/source/MongoDB/LinqExtensions.cs. We did something very similiar with the old driver and the linq provider was transplanted from there to here. I assume the same thing will work.
The GetQuery method at the bottom is how to get the query document out of the IQueryable instance.
Please update to support Linq Collection.Update()