db4o:LINQ 相当于 SODA 查询?
对于 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您真的想直接使用 query.Descend("Symbol"); 下降到“Symbol”吗?我猜你想限制“符号”类型。我只是假设你的意思是这样的:
不是100%确定,但应该是这样的:
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:Not 100% sure, but should be something like this: