1 //---------------------------------------------------------------------
2 // <copyright file="EntitySqlParser.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
10 namespace System.Data.Common.EntitySql
12 using System.Collections.Generic;
13 using System.Data.Common.CommandTrees;
14 using System.Data.Common.EntitySql;
15 using System.Data.Common.Utils;
16 using System.Data.Metadata.Edm;
17 using System.Diagnostics;
20 /// Public Entity SQL Parser class.
22 public sealed class EntitySqlParser
24 private readonly Perspective _perspective;
27 /// Construct a parser bound to the specified workspace with the specified perspective.
29 internal EntitySqlParser(Perspective perspective)
31 Debug.Assert(null != perspective, "null perspective?");
32 _perspective = perspective;
36 /// Parse the specified <paramref name="query"/> with the specified <paramref name="parameters"/>.
38 /// <param name="query">EntitySQL query to be parsed.</param>
39 /// <param name="parameters">optional query parameters</param>
40 /// <returns><see cref="ParseResult"/> containing <see cref="DbCommandTree"/> and information describing inline function definitions if any.</returns>
41 public ParseResult Parse(string query, params DbParameterReferenceExpression[] parameters)
43 EntityUtil.CheckArgumentNull(query, "query");
44 if (parameters != null)
46 IEnumerable<DbParameterReferenceExpression> paramsEnum = parameters;
47 EntityUtil.CheckArgumentContainsNull(ref paramsEnum, "parameters");
50 var result = CqlQuery.Compile(query, _perspective, null /* parser options - use default */, parameters);
55 /// Parse a specific query with a specific set variables and produce a <see cref="DbLambda"/>.
57 public DbLambda ParseLambda(string query, params DbVariableReferenceExpression[] variables)
59 EntityUtil.CheckArgumentNull(query, "query");
60 if (variables != null)
62 IEnumerable<DbVariableReferenceExpression> varsEnum = variables;
63 EntityUtil.CheckArgumentContainsNull(ref varsEnum, "variables");
66 DbLambda result = CqlQuery.CompileQueryCommandLambda(query, _perspective, null /* parser options - use default */, null /* parameters */, variables);