2
votes

1.) Is it possible to do a DISTINCT query in LINQ? Like the equivalent of the the AQL query below?

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

2.) Is it possible to do "LET doc = DOCUMENT(some._id)"? I tried something like the query below but got an exception about Document not being supported.

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

3.) How do you do raw AQL queries with bind parameters? I tried CreateStatement(), but couldn't get it to do the parameter replacement ('evts' is an IEnumerable with some document IDs).

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

Debug Output:

==============================
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
1

1 Answers

1
votes

I figured out #3. I needed to remove the @ from the parameter, but leave it in the query (I thought I tried that before posting, but I guess it was every other combination).

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