【问题标题】:ArangoDB .NET Client: Various questions about queries (DISTINCT, LET/DOCUMENT, raw AQL)ArangoDB .NET 客户端:关于查询的各种问题(DISTINCT、LET/DOCUMENT、原始 AQL)
【发布时间】:2017-05-11 18:09:15
【问题描述】:

1.) 是否可以在 LINQ 中执行 DISTINCT 查询?类似于下面的 AQL 查询?

FOR cfg IN test_configuration
    FOR method IN inspection_method
        FILTER cfg.inspection_method_id == method._id
        SORT method.name
        RETURN DISTINCT method

2.) 是否可以执行“LET doc = DOCUMENT(some._id)”?我尝试了类似下面的查询,但得到了关于 Document not being supported 的异常。

from user in users
  let dept = db.Document<Department>(user.department_id)
  where dept.name == "lingerie"
  select user

3.) 如何使用绑定参数执行原始 AQL 查询?我尝试了 CreateStatement(),但无法让它进行参数替换('evts' 是一个带有一些文档 ID 的 IEnumerable)。

List<ArangoDB.Client.Data.QueryParameter> parameters = new List<ArangoDB.Client.Data.QueryParameter>() {
    new ArangoDB.Client.Data.QueryParameter() {
        Name = "@P1",
        Value = evts,
    },
};

query = Database.CreateStatement<InspectionMethod>(@"
    FOR cfg IN test_configuration
        FOR method IN inspection_method
            FILTER cfg.inspection_method_id == method._id AND cfg.test_event_id IN @P1
            SORT method.name
            RETURN DISTINCT method", parameters)
            .AsEnumerable().AsQueryable();

调试输出:

==============================
5/11/2017 2:02:54 PM
creating an AQL query:
query: 
FOR cfg IN test_configuration
    FOR method IN inspection_method
        FILTER cfg.inspection_method_id == method._id AND cfg.test_event_id IN @P1
        SORT method.name
        RETURN DISTINCT method
bindVars:
name: @P1 value: ["test_event/7250917"]

parsed query with variables replaced:

FOR cfg IN test_configuration
    FOR method IN inspection_method
        FILTER cfg.inspection_method_id == method._id AND cfg.test_event_id IN @P1
        SORT method.name
        RETURN DISTINCT method

【问题讨论】:

    标签: c# .net arangodb


    【解决方案1】:

    我想出了#3。我需要从参数中删除 @,但将其保留在查询中(我以为我在发布之前尝试过,但我猜这是所有其他组合)。

    List<ArangoDB.Client.Data.QueryParameter> parameters = new List<ArangoDB.Client.Data.QueryParameter>() {
        new ArangoDB.Client.Data.QueryParameter() {
            Name = "P1",
            Value = evts,
        },
    };
    
    query = Database.CreateStatement<InspectionMethod>(@"
        FOR cfg IN test_configuration
            FOR method IN inspection_method
                FILTER cfg.inspection_method_id == method._id AND cfg.test_event_id IN @P1
                SORT method.name
                RETURN DISTINCT method", parameters)
                .AsEnumerable().AsQueryable();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多