/// <summary> /// Get the query text for the calling method. /// </summary> /// <remarks> /// <see cref="QueryUtilities.GetEmbeddedQuery" />, <see cref="QueryUtilities.Preprocess"/> and <see cref="QueryUtilities.Minify" /> for more details. /// The resulting query text is cached by each repository on a per-class basis so each query is only extracted and /// minified once. /// </remarks> /// <param name="preprocessorFlags">A dictionary of named booleans necessary if using any preprocessor directives.</param> /// <param name="queryName">The name of the query to get. This defaults to the calling method.</param> /// <returns>The query text (minified).</returns> protected string GetQuery(IDictionary <string, bool> preprocessorFlags, [CallerMemberName] string queryName = null) { if (preprocessorFlags == null) { throw new ArgumentNullException(nameof(queryName)); } if (queryName == null) { throw new ArgumentNullException(nameof(queryName)); } var type = GetType(); var flagsKey = GetPreProcessorIdentifier(preprocessorFlags); var fullName = $"{type.FullName}.{queryName}({flagsKey})"; return(Queries.GetOrAdd(fullName, x => { var q1 = QueriesRaw.GetOrAdd(fullName, y => { var q2 = QueryUtilities.GetEmbeddedQuery(queryName, type); return QueryUtilities.Preprocess(preprocessorFlags, q2); }); return QueryUtilities.Minify(q1); })); }
/// <summary> /// Get the query text for the calling method. /// <see cref="QueryUtilities.GetEmbeddedQuery" /> for more details. /// The resulting query text is cached by each repository on a per-class basis so each query is only extracted and /// minified once. /// </summary> /// <param name="queryName">The name of the query to get. This defaults to the calling method.</param> /// <returns>The query text (unminified).</returns> protected string GetQueryRaw([CallerMemberName] string queryName = null) { if (queryName == null) { throw new ArgumentNullException(nameof(queryName)); } var type = GetType(); var fullName = $"{type.FullName}.{queryName}()"; return(QueriesRaw.GetOrAdd(fullName, x => { var q = QueryUtilities.GetEmbeddedQuery(queryName, type); var preprocessorFlags = new Dictionary <string, bool>(); return QueryUtilities.Preprocess(preprocessorFlags, q); })); }