private DbCommandTree MakeCommandTree() { DbCommandTree dbCommandTree = (DbCommandTree)null; if (this._commandTreeSetByUser != null) { dbCommandTree = this._commandTreeSetByUser; } else if (CommandType.Text == this.CommandType) { if (!string.IsNullOrEmpty(this._esqlCommandText)) { dbCommandTree = CqlQuery.Compile(this._esqlCommandText, (Perspective) new ModelPerspective(this._connection.GetMetadataWorkspace()), (ParserOptions)null, this.GetParameterTypeUsage().Select <KeyValuePair <string, TypeUsage>, DbParameterReferenceExpression>((Func <KeyValuePair <string, TypeUsage>, DbParameterReferenceExpression>)(paramInfo => paramInfo.Value.Parameter(paramInfo.Key)))).CommandTree; } else { if (this._isCommandDefinitionBased) { throw new InvalidOperationException(Strings.EntityClient_CannotReprepareCommandDefinitionBasedCommand); } throw new InvalidOperationException(Strings.EntityClient_NoCommandText); } } else if (CommandType.StoredProcedure == this.CommandType) { dbCommandTree = (DbCommandTree) new DbFunctionCommandTree(this.Connection.GetMetadataWorkspace(), DataSpace.CSpace, this.DetermineFunctionImport(), (TypeUsage)null, (IEnumerable <KeyValuePair <string, TypeUsage> >) this.GetParameterTypeUsage()); } return(dbCommandTree); }
/// <summary> /// Ensures we have the command tree, either the user passed us the tree, or an eSQL statement that we need to parse /// </summary> private void MakeCommandTree() { // We must have a connection before we come here Debug.Assert(this._connection != null); // Do the work only if we don't have a command tree yet if (this._preparedCommandTree == null) { DbCommandTree resultTree = null; if (this._commandTreeSetByUser != null) { resultTree = this._commandTreeSetByUser; } else if (CommandType.Text == CommandType) { if (!string.IsNullOrEmpty(this._esqlCommandText)) { // The perspective to be used for the query compilation Perspective perspective = (Perspective) new ModelPerspective(_connection.GetMetadataWorkspace()); // get a dictionary of names and typeusage from entity parameter collection Dictionary <string, TypeUsage> queryParams = GetParameterTypeUsage(); resultTree = CqlQuery.Compile( this._esqlCommandText, perspective, null /*parser option - use default*/, queryParams.Select(paramInfo => paramInfo.Value.Parameter(paramInfo.Key))).CommandTree; } else { // We have no command text, no command tree, so throw an exception if (this._isCommandDefinitionBased) { // This command was based on a prepared command definition and has no command text, // so reprepare is not possible. To create a new command with different parameters // requires creating a new entity command definition and calling it's CreateCommand method. throw EntityUtil.InvalidOperation(System.Data.Entity.Strings.EntityClient_CannotReprepareCommandDefinitionBasedCommand); } else { throw EntityUtil.InvalidOperation(System.Data.Entity.Strings.EntityClient_NoCommandText); } } } else if (CommandType.StoredProcedure == CommandType) { // get a dictionary of names and typeusage from entity parameter collection IEnumerable <KeyValuePair <string, TypeUsage> > queryParams = GetParameterTypeUsage(); EdmFunction function = DetermineFunctionImport(); resultTree = new DbFunctionCommandTree(this.Connection.GetMetadataWorkspace(), DataSpace.CSpace, function, null, queryParams); } // After everything is good and succeeded, assign the result to our field this._preparedCommandTree = resultTree; } }
// <summary> // Ensures we have the command tree, either the user passed us the tree, or an eSQL statement that we need to parse // </summary> private DbCommandTree MakeCommandTree() { // We must have a connection before we come here Debug.Assert(_connection != null); DbCommandTree resultTree = null; if (_commandTreeSetByUser != null) { resultTree = _commandTreeSetByUser; } else if (CommandType.Text == CommandType) { if (!string.IsNullOrEmpty(_esqlCommandText)) { // The perspective to be used for the query compilation Perspective perspective = new ModelPerspective(_connection.GetMetadataWorkspace()); // get a dictionary of names and typeusage from entity parameter collection var queryParams = GetParameterTypeUsage(); resultTree = CqlQuery.Compile( _esqlCommandText, perspective, null /*parser option - use default*/, queryParams.Select(paramInfo => paramInfo.Value.Parameter(paramInfo.Key))).CommandTree; } else { // We have no command text, no command tree, so throw an exception if (_isCommandDefinitionBased) { // This command was based on a prepared command definition and has no command text, // so reprepare is not possible. To create a new command with different parameters // requires creating a new entity command definition and calling it's CreateCommand method. throw new InvalidOperationException(Strings.EntityClient_CannotReprepareCommandDefinitionBasedCommand); } else { throw new InvalidOperationException(Strings.EntityClient_NoCommandText); } } } else if (CommandType.StoredProcedure == CommandType) { // get a dictionary of names and typeusage from entity parameter collection IEnumerable <KeyValuePair <string, TypeUsage> > queryParams = GetParameterTypeUsage(); var function = DetermineFunctionImport(); resultTree = new DbFunctionCommandTree(Connection.GetMetadataWorkspace(), DataSpace.CSpace, function, null, queryParams); } return(resultTree); }
internal static DbCommandTree CompileView( string viewDef, StorageMappingItemCollection mappingItemCollection, ParserOptions.CompilationMode compilationMode) { Perspective perspective = (Perspective) new TargetPerspective(mappingItemCollection.Workspace); return(CqlQuery.Compile(viewDef, perspective, new ParserOptions() { ParserCompilationMode = compilationMode }, (IEnumerable <DbParameterReferenceExpression>)null).CommandTree); }
internal static DbCommandTree CompileView( string viewDef, StorageMappingItemCollection mappingItemCollection, ParserOptions.CompilationMode compilationMode) { DebugCheck.NotEmpty(viewDef); DebugCheck.NotNull(mappingItemCollection); Perspective perspective = new TargetPerspective(mappingItemCollection.Workspace); var parserOptions = new ParserOptions(); parserOptions.ParserCompilationMode = compilationMode; var expr = CqlQuery.Compile(viewDef, perspective, parserOptions, null).CommandTree; Debug.Assert(expr != null, "Compile returned empty tree?"); return(expr); }
static internal DbCommandTree CompileView( string viewDef, StorageMappingItemCollection mappingItemCollection, ParserOptions.CompilationMode compilationMode) { Debug.Assert(!String.IsNullOrEmpty(viewDef), "!String.IsNullOrEmpty(viewDef)"); Debug.Assert(mappingItemCollection != null, "mappingItemCollection != null"); Perspective perspective = new TargetPerspective(mappingItemCollection.Workspace); ParserOptions parserOptions = new ParserOptions(); parserOptions.ParserCompilationMode = compilationMode; DbCommandTree expr = CqlQuery.Compile(viewDef, perspective, parserOptions, null).CommandTree; Debug.Assert(expr != null, "Compile returned empty tree?"); return(expr); }