I just checked in some code to simplify querying. I will just let the code speak for itself.
var q = new Query()["Name"].In("Daniel", "Sue").And("Age").Gt(21).And().Lt(29);
var persons = entityStore.Find(q.ToString());
So far it only supports:
- $in
- $where
- $lt
- $lte
- $gt
- $gte
I will continue the work with the inner design of this Querying-code, but the API will be the same. I will of course add more operators to.
//Daniel
Advertisement
[...] with 2 comments Updated: Read more about Simplified Querying [...]
Hi, I really like using your library. But I can’t get this code sample to work. The Query calls require a , and so I get a compiler error. I’d really like to be able to use anonymous objects since some of the docs in my collection vary in structure. Is there a different code branch I need to install?
Also, is there a way in Simo to get back just a raw JSON string in a query? That would be nice so I can pass it back down to the browser. (I’m using Simo with ASP.NET MVC.)
Thanks!
Jeff
Actually, I take that back — the error I’m getting is this:
Pls.SimpleMongoDb.Querying.Query.Query() is inaccessible due to the protection level.
Since I have the source, can I just change it to public to make it work?
Hi again, looks like I found a different way to do what I need. I just created an empty class that matches the name of the collection:
class testcollection { };
From there I can just use the session API:
var sessionFactory = new SimoSessionFactory();
using (var session = sessionFactory.GetSession(“Pls.Simo.GettingStarted”)) {
var db = session["test"];
var collection = db.GetCollection();
var result = collection.Find();
foreach (var doc in result) {
Console.WriteLine(doc);
}
}
It works!
Great that it worked out. You do know that I haven’t put any time to the driver in a long time? I might pick it up again and do some adjustments: perf, json-driver, lambda expressions. Interested in joining? Just for fun.
//Daniel