0

对于 db4o,我试图找到生成以下 SODA 的 LINQ 代码:

    var query = db4o.db.Query();
    query.Descend("Symbol");        
    query.Descend("_symbolGlobal").Constrain("APPLE");
    query.Descend("_date"); // Add a date constraint here.
    IObjectSet result = query.Execute();

SODA 所做的只是将树下拉到一个结束节点。例如,如果您想为日期“2010-10-18”选择“APPLE”,它将返回“Apples on Thursday”。

数据结构:

Root ----Symbol (APPLE)                
   |          |------Day 1: Date: 2010-10-18, string "Apples on Thursday"
   |          |------Day 2: Date: 2010-10-19, string "Apples on Friday"
   |
   |
   |-----Symbol (PEAR)               
              |------Day 1: Date: 2010-10-18, string "Pears on Thursday"
              |------Day 2: Date: 2010-10-19, string "Pears on Friday"

这是我的第一次尝试,它不能作为它获得交叉产品(即它查看每个可能的组合)。我不能使用连接,因为 db4o 是一个对象数据库,您无法访问每个对象的 ID,就像在 RDBMS 中一样。

    var stringForDayAndSymbol = from s in db4o.db.Query<Symbol>(a => a.SymbolGlobal == "APPLE")
                          from t in db4o.db.Query<Date>(b => b.Date == new DateTime(2010, 10, 20))
                          select new
                          {
                            s.SymbolGlobal,
                            t.Date,
                            t.Meta
                          };
4

1 回答 1

1

你真的想直接下降到“符号”query.Descend("Symbol");吗?我猜您想限制“符号”类型。我只是假设您的意思是:

var query = db4o.db.Query();
query.Constrain(typeof(Symbol));        
query.Descend("_symbolGlobal").Constrain("APPLE");
query.Descend("_date"); // Add a date constraint here.
IObjectSet result = query.Execute();

不是 100% 确定,但应该是这样的:

// I assume here that the field _symbolGlobal is accessable with the property SymbolGlobal
// and the field _date is accessable with the property Date
var result = from Symbol s in db4o.db
            where s.SymbolGlobal == "APPLE"  
            select s.Date;
于 2011-02-23T19:47:14.940 回答