Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a way to submit additional query parameters while executing a LINQ query as a cursor #100

Open
wants to merge 2 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/ArangoDB.Client/Extentions/QueryableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ public static ICursor<T> AsCursor<T>(this IQueryable<T> source)
return source.AsArangoQueryable<T>().AsCursor();
}

public static ICursor<T> AsCursor<T>(this IQueryable<T> source, bool? count = null, int? batchSize = null, TimeSpan? ttl = null, QueryOption options = null)
{
return source.AsArangoQueryable<T>().AsCursor(count, batchSize, ttl, options);
}

public static void Execute<T>(this IAqlModifiable<T> source)
{
// AsCursor is needed for executing query by ArangoQueryable methods instead of ArangoQueryExecuter
Expand Down
4 changes: 1 addition & 3 deletions src/ArangoDB.Client/Property/DatabaseCollectionSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,7 @@ internal string ResolvePropertyName(Type type, string memberName)

public string ResolvePropertyName<T>(Expression<Func<T, object>> attribute)
{
var memberInfo = Utils.GetMemberInfo<T>(attribute);

return ResolvePropertyName(typeof(T), memberInfo.Name);
return ResolvePropertyName(typeof(T), Utils.GetPropertyName(attribute));
}

internal string ResolveNestedPropertyName<T>(Expression<Func<T, object>> attribute)
Expand Down
6 changes: 5 additions & 1 deletion src/ArangoDB.Client/Property/DocumentPropertySetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ internal static IDocumentPropertySetting FindDocumentAttributeForType(Type type,
cachedAttributeProperties.TryAdd(type, typeSetting);
}

return typeSetting[memberName];
//check if the property existing in the dictionary and return it in case it does
if (typeSetting.TryGetValue(memberName, out IDocumentPropertySetting documentPropertySetting))
return documentPropertySetting;

return null;
}

internal static IDocumentPropertySetting FindDocumentAttributeForType<T>(Expression<Func<T, object>> attribute)
Expand Down
6 changes: 6 additions & 0 deletions src/ArangoDB.Client/Query/ArangoQueryable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,11 @@ public ICursor<T> AsCursor()
return db.CreateStatement<T>(queryData.Query
, bindVars: queryData.BindVars);
}

public ICursor<T> AsCursor(bool? count = null, int? batchSize = null, TimeSpan? ttl = null, QueryOption options = null)
{
var queryData = GetQueryData();
return db.CreateStatement<T>(queryData.Query, queryData.BindVars, count, batchSize, ttl, options);
}
}
}
22 changes: 22 additions & 0 deletions src/ArangoDB.Client/Utility/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,28 @@ public static string ResolveId(string id, string collectionName = null)
}
}

public static string GetPropertyName<TModel, TValue>(Expression<Func<TModel, TValue>> attribute)
{
const char delimiterDot = '.';
const char delimiterPlus = '+';
const char delimiterComma = ',';
const char endTrim = ')';

var asString = attribute.ToString(); // gives you: "o => o.Whatever"
//now we need to replace the plus signs with the dots in case of the nesting classes
asString = asString.Replace(delimiterPlus, delimiterDot);
// make sure there is a beginning property indicator; the "." in "o.Whatever"
var firstDotDelim = asString.IndexOf(delimiterDot);
var firstCommaDelim = asString.IndexOf(delimiterComma);

if (firstDotDelim < 0)
return asString;
else if (firstCommaDelim < 0)
return asString.Substring(firstDotDelim + 1).TrimEnd(endTrim);
else
return asString.Substring(firstDotDelim + 1, firstCommaDelim - firstDotDelim - 1);
}

public static MemberInfo GetMemberInfo<T>(Expression<Func<T, object>> attribute)
{
return GetMemberExpression(attribute).Member;
Expand Down