db4o:LINQ 相当于 SODA 查询?

发布于 2024-10-19 01:31:52 字数 1341 浏览 1 评论 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 Friday”。

数据结构:

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

For db4o, I'm trying to find the LINQ code that generates the following SODA:

    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();

All the SODA does is drop down the tree to an end node. For example, if you wanted to select "APPLE" for date "2010-10-18", it would return "Apples on Thursday".

Data structure:

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"

Here is my first attempt, which doesn't work as its getting the cross product (i.e. its looking at every possible combination). I can't use a join, as db4o is an object database and you don't have access to the ID for each object, like in a 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
                          };

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

盗梦空间 2024-10-26 01:31:52

您真的想直接使用 query.Descend("Symbol"); 下降到“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;

Do you really directly want to descent into "Symbol" with query.Descend("Symbol");? I guess that you want to constrain for the type 'Symbol'. I just assume that you meant this:

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();

Not 100% sure, but should be something like this:

// 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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文