Lambda syntax in linq for db4o?

I know what is possible with linq2db4o

from Apple a in db
where a.Color.Equals(Colors.Green)
select a

What I need, but this is what allows me to build my query conditionally (as I can in other linq variants)

public IEnumerable<Apple> SearchApples (AppleSearchbag bag){
    var q = db.Apples;
    if(bag.Color != null){
        q = q.Where(a=>a.Color.Equals(bag.Color));
    }
    return q.AsEnumerable();
}

In a real situation, a lot of properties will be stored in a search package, and creating a giant if-tree that catches all possible combinations of filled properties will be crazy work.

You can call first

var q = (from Color c in db select c);

and then continue from there. but that’s not quite what I am looking for.

Disclaimer: almost a duplicate of my question almost 11 months ago.
This is a little clearer, as I now understand, and now I hope that some of the db4o dev eyes will understand this on this:

Any suggestions?

+3
1

, , LINQ, db4o. , db :

IObjectContainer db;

:

public IEnumerable<Apple> SearchApples (AppleSearchbag bag)
{
    var query = db.Cast<Apple> ();
    // query will be a Db4objects.Db4o.Linq.IDb4oLinqQuery<Apple>
    if (bag.Color != null)
        query = query.Where (a => a.Color == bag.Color);

    return query;
}

, .

- IQueryable, , :

public IQueryable<Apple> SearchApples (AppleSearchbag bag)
{
    var query = db.AsQueryable<Apple> ();
    // query will be a System.Linq.IQueryble<Apple>
    if (bag.Color != null)
        query = query.Where (a => a.Color == bag.Color);

    return query;
}

db4o , , LINQ . , , LINQ db4o.

+6

Source: https://habr.com/ru/post/1724387/


All Articles