2011-02-23 26 views
0

对于db4o的,我试图找到产生以下SODA的LINQ代码: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”,则会返回“周四的苹果”。

数据结构:

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 
          }; 

回答

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; 
+0

我已经打上这个答案是正确的,但是,如果你试图降落成为一个对象的集合,比如任何用IList实例化的对象,那么它将不起作用(集合对于SODA来说似乎是不可见的)。 – Contango

+0

嗯,我认为集合上的'contains'操作也应该与LINQ一起工作。像s.SymbolGlobal.Contains(“Apple”)。 – Gamlor