//---------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner Microsoft
// @backupOwner Microsoft
//---------------------------------------------------------------------
namespace System.Data.Common.EntitySql
{
using System.Collections.Generic;
using System.Data.Common.CommandTrees;
using System.Data.Common.EntitySql;
using System.Data.Common.Utils;
using System.Data.Metadata.Edm;
using System.Diagnostics;
///
/// Public Entity SQL Parser class.
///
public sealed class EntitySqlParser
{
private readonly Perspective _perspective;
///
/// Construct a parser bound to the specified workspace with the specified perspective.
///
internal EntitySqlParser(Perspective perspective)
{
Debug.Assert(null != perspective, "null perspective?");
_perspective = perspective;
}
///
/// Parse the specified with the specified .
///
/// EntitySQL query to be parsed.
/// optional query parameters
/// containing and information describing inline function definitions if any.
public ParseResult Parse(string query, params DbParameterReferenceExpression[] parameters)
{
EntityUtil.CheckArgumentNull(query, "query");
if (parameters != null)
{
IEnumerable paramsEnum = parameters;
EntityUtil.CheckArgumentContainsNull(ref paramsEnum, "parameters");
}
var result = CqlQuery.Compile(query, _perspective, null /* parser options - use default */, parameters);
return result;
}
///
/// Parse a specific query with a specific set variables and produce a .
///
public DbLambda ParseLambda(string query, params DbVariableReferenceExpression[] variables)
{
EntityUtil.CheckArgumentNull(query, "query");
if (variables != null)
{
IEnumerable varsEnum = variables;
EntityUtil.CheckArgumentContainsNull(ref varsEnum, "variables");
}
DbLambda result = CqlQuery.CompileQueryCommandLambda(query, _perspective, null /* parser options - use default */, null /* parameters */, variables);
return result;
}
}
}