Thursday 15 January 2015

c# - Lambda syntax in linq to db4o? -


I know that with the following possible linq2db4o

  to AB dB where a Colour. Eclocks (Colors.Green)  

What do I need, something that allows me to conditionally create my query (like I can do in other Linux forms)

  public IEnumerable & lt; Apple & gt; Searchple's bag (apple search bag bag) {var q = db.Apples; If (bag.color! = Null) {q = q.Where (a => a.color.Equals (bag color)); } Return q.Asumerable (); }  

In a real situation, searchbags will maintain many properties and will create a giant if tree that will catch all the possible combinations of loaded properties, they will go crazy.

It is possible to call first

  var q = (db in select c in color c);  

And then continue from there, but this is not what I am searching for.

Disclaimer: Approximately 11 months prior to duplicate.
It is a bit more obvious because I think this topic is better and I hope now some db4o god eyes can catch it on:

Any suggestions?

Yes, it is definitely possible to build custom LINQ queries using DB4O . It is valid that DB is defined as:

  IObjectContainer db;  

Your query is:

  Public INMEMALABLE & lt; Apple & gt; Searchpeople (apple search bag bag) {var query = db. Cast & LT; Apple & gt; (); // query a Db4objects.Db4o.Linq.IDb4oLinqQuery & lt; Apple & gt; If (bag.color! = Null) query = query Where (a => a.color == bag.Color); Return query; }  

In that case, whenever the returnable number is being repeated, then the query will be executed.

Another possibility is to use the IQueryable mechanism, which is well-known by developers:

  Public IQueryable & lt; Apple & gt; Searchpeople (apple search bag bag) {var query = db.exchangeable & lt; Apple & gt; (); // query will be a system. Link Equitable & lt; Apple & gt; If (bag.color! = Null) query = query Where (a => a.color == bag.Color); Return query; }  

In both cases, the db4o will try to remove a customized query from the lambda expression on execution, and if it fails, then the LINQ will fallback to the object.

By avoiding queries from LINQ, the first one has more advantage.

No comments:

Post a Comment