internal DbDeleteCommandTree(MetadataWorkspace metadata, DataSpace dataSpace, DbExpressionBinding target, DbExpression predicate) : base(metadata, dataSpace, target) { //Contract.Requires(predicate != null); _predicate = predicate; }
internal DbModificationCommandTree(MetadataWorkspace metadata, DataSpace dataSpace, DbExpressionBinding target) : base(metadata, dataSpace) { EntityUtil.CheckArgumentNull(target, "target"); this._target = target; }
internal DbDeleteCommandTree(MetadataWorkspace metadata, DataSpace dataSpace, DbExpressionBinding target, DbExpression predicate) : base(metadata, dataSpace, target) { EntityUtil.CheckArgumentNull(predicate, "predicate"); this._predicate = predicate; }
public override DbExpression Visit(DbJoinExpression expression) { EntityUtil.CheckArgumentNull(expression, "expression"); DbExpression result = expression; DbExpressionBinding newLeft = this.VisitExpressionBinding(expression.Left); DbExpressionBinding newRight = this.VisitExpressionBinding(expression.Right); this.EnterScope(newLeft.Variable, newRight.Variable); DbExpression newCondition = this.VisitExpression(expression.JoinCondition); this.ExitScope(); if (!object.ReferenceEquals(expression.Left, newLeft) || !object.ReferenceEquals(expression.Right, newRight) || !object.ReferenceEquals(expression.JoinCondition, newCondition)) { if (DbExpressionKind.InnerJoin == expression.ExpressionKind) { result = CqtBuilder.InnerJoin(newLeft, newRight, newCondition); } else if (DbExpressionKind.LeftOuterJoin == expression.ExpressionKind) { result = CqtBuilder.LeftOuterJoin(newLeft, newRight, newCondition); } else { Debug.Assert(expression.ExpressionKind == DbExpressionKind.FullOuterJoin, "DbJoinExpression had ExpressionKind other than InnerJoin, LeftOuterJoin or FullOuterJoin?"); result = CqtBuilder.FullOuterJoin(newLeft, newRight, newCondition); } } NotifyIfChanged(expression, result); return(result); }
public override DbExpression Visit(DbApplyExpression expression) { EntityUtil.CheckArgumentNull(expression, "expression"); DbExpression result = expression; DbExpressionBinding newInput = this.VisitExpressionBindingEnterScope(expression.Input); DbExpressionBinding newApply = this.VisitExpressionBinding(expression.Apply); this.ExitScope(); if (!object.ReferenceEquals(expression.Input, newInput) || !object.ReferenceEquals(expression.Apply, newApply)) { if (DbExpressionKind.CrossApply == expression.ExpressionKind) { result = CqtBuilder.CrossApply(newInput, newApply); } else { Debug.Assert(expression.ExpressionKind == DbExpressionKind.OuterApply, "DbApplyExpression had ExpressionKind other than CrossApply or OuterApply?"); result = CqtBuilder.OuterApply(newInput, newApply); } } NotifyIfChanged(expression, result); return(result); }
internal DbModificationCommandTree(MetadataWorkspace metadata, DataSpace dataSpace, DbExpressionBinding target) : base(metadata, dataSpace) { EntityUtil.CheckArgumentNull(target, "target"); this._target = target; }
public override DbExpression Visit(DbQuantifierExpression expression) { EntityUtil.CheckArgumentNull(expression, "expression"); DbExpression result = expression; DbExpressionBinding input = this.VisitExpressionBindingEnterScope(expression.Input); DbExpression predicate = this.VisitExpression(expression.Predicate); this.ExitScope(); if (!object.ReferenceEquals(expression.Input, input) || !object.ReferenceEquals(expression.Predicate, predicate)) { if (DbExpressionKind.All == expression.ExpressionKind) { result = CqtBuilder.All(input, predicate); } else { Debug.Assert(expression.ExpressionKind == DbExpressionKind.Any, "DbQuantifierExpression had ExpressionKind other than All or Any?"); result = CqtBuilder.Any(input, predicate); } } NotifyIfChanged(expression, result); return(result); }
private DbExpressionBinding VisitExpressionBindingEnterScope(DbExpressionBinding binding) { DbExpressionBinding result = this.VisitExpressionBinding(binding); this.OnEnterScope(new[] { result.Variable }); return(result); }
internal DbModificationCommandTree(MetadataWorkspace metadata, DataSpace dataSpace, DbExpressionBinding target) : base(metadata, dataSpace) { //Contract.Requires(target != null); _target = target; }
internal DbInsertCommandTree(MetadataWorkspace metadata, DataSpace dataSpace, DbExpressionBinding target, ReadOnlyModificationClauses setClauses, DbExpression returning) : base(metadata, dataSpace, target) { EntityUtil.CheckArgumentNull(setClauses, "setClauses"); // returning may be null this._setClauses = setClauses; this._returning = returning; }
internal DbProjectExpression(TypeUsage resultType, DbExpressionBinding input, DbExpression projection) : base(DbExpressionKind.Project, resultType) { Debug.Assert(input != null, "DbProjectExpression input cannot be null"); Debug.Assert(projection != null, "DbProjectExpression projection cannot be null"); this._input = input; this._projection = projection; }
internal DbApplyExpression(DbExpressionKind applyKind, TypeUsage resultRowCollectionTypeUsage, DbExpressionBinding input, DbExpressionBinding apply) : base(applyKind, resultRowCollectionTypeUsage) { Debug.Assert(input != null, "DbApplyExpression input cannot be null"); Debug.Assert(input != null, "DbApplyExpression apply cannot be null"); Debug.Assert(DbExpressionKind.CrossApply == applyKind || DbExpressionKind.OuterApply == applyKind, "Invalid DbExpressionKind for DbApplyExpression"); _input = input; _apply = apply; }
internal DbSortExpression(TypeUsage resultType, DbExpressionBinding input, System.Collections.ObjectModel.ReadOnlyCollection <DbSortClause> sortOrder) : base(DbExpressionKind.Sort, resultType) { Debug.Assert(input != null, "DbSortExpression input cannot be null"); Debug.Assert(sortOrder != null, "DbSortExpression sort order cannot be null"); Debug.Assert(TypeSemantics.IsCollectionType(resultType), "DbSkipExpression requires a collection result type"); this._input = input; this._keys = sortOrder; }
internal DbFilterExpression(TypeUsage resultType, DbExpressionBinding input, DbExpression predicate) : base(DbExpressionKind.Filter, resultType) { Debug.Assert(input != null, "DbFilterExpression input cannot be null"); Debug.Assert(predicate != null, "DbBFilterExpression predicate cannot be null"); Debug.Assert(TypeSemantics.IsPrimitiveType(predicate.ResultType, PrimitiveTypeKind.Boolean), "DbFilterExpression predicate must have a Boolean result type"); _input = input; _predicate = predicate; }
internal DbQuantifierExpression(DbExpressionKind kind, TypeUsage booleanResultType, DbExpressionBinding input, DbExpression predicate) : base(kind, booleanResultType) { Debug.Assert(input != null, "DbQuantifierExpression input cannot be null"); Debug.Assert(predicate != null, "DbQuantifierExpression predicate cannot be null"); Debug.Assert(TypeSemantics.IsPrimitiveType(booleanResultType, PrimitiveTypeKind.Boolean), "DbQuantifierExpression must have a Boolean result type"); Debug.Assert(TypeSemantics.IsPrimitiveType(predicate.ResultType, PrimitiveTypeKind.Boolean), "DbQuantifierExpression predicate must have a Boolean result type"); this._input = input; this._predicate = predicate; }
internal DbUpdateCommandTree(MetadataWorkspace metadata, DataSpace dataSpace, DbExpressionBinding target, DbExpression predicate, ReadOnlyModificationClauses setClauses, DbExpression returning) : base(metadata, dataSpace, target) { EntityUtil.CheckArgumentNull(predicate, "predicate"); EntityUtil.CheckArgumentNull(setClauses, "setClauses"); // returning is allowed to be null this._predicate = predicate; this._setClauses = setClauses; this._returning = returning; }
internal DbInsertCommandTree( MetadataWorkspace metadata, DataSpace dataSpace, DbExpressionBinding target, ReadOnlyModificationClauses setClauses, DbExpression returning) : base(metadata, dataSpace, target) { //Contract.Requires(setClauses != null); // returning may be null _setClauses = setClauses; _returning = returning; }
internal DbUpdateCommandTree( MetadataWorkspace metadata, DataSpace dataSpace, DbExpressionBinding target, DbExpression predicate, ReadOnlyModificationClauses setClauses, DbExpression returning) : base(metadata, dataSpace, target) { //Contract.Requires(predicate != null); //Contract.Requires(setClauses != null); // returning is allowed to be null _predicate = predicate; _setClauses = setClauses; _returning = returning; }
internal DbJoinExpression(DbExpressionKind joinKind, TypeUsage collectionOfRowResultType, DbExpressionBinding left, DbExpressionBinding right, DbExpression condition) : base(joinKind, collectionOfRowResultType) { Debug.Assert(left != null, "DbJoinExpression left cannot be null"); Debug.Assert(right != null, "DbJoinExpression right cannot be null"); Debug.Assert(condition != null, "DbJoinExpression condition cannot be null"); Debug.Assert(DbExpressionKind.InnerJoin == joinKind || DbExpressionKind.LeftOuterJoin == joinKind || DbExpressionKind.FullOuterJoin == joinKind, "Invalid DbExpressionKind specified for DbJoinExpression"); _left = left; _right = right; _condition = condition; }
protected virtual DbExpressionBinding VisitExpressionBinding(DbExpressionBinding binding) { DbExpressionBinding result = binding; if (binding != null) { DbExpression newInput = this.VisitExpression(binding.Expression); if (!object.ReferenceEquals(binding.Expression, newInput)) { result = CqtBuilder.BindAs(newInput, binding.VariableName); this.RebindVariable(binding.Variable, result.Variable); } } return(result); }
public override DbExpression Visit(DbProjectExpression expression) { EntityUtil.CheckArgumentNull(expression, "expression"); DbExpression result = expression; DbExpressionBinding input = this.VisitExpressionBindingEnterScope(expression.Input); DbExpression projection = this.VisitExpression(expression.Projection); this.ExitScope(); if (!object.ReferenceEquals(expression.Input, input) || !object.ReferenceEquals(expression.Projection, projection)) { result = CqtBuilder.Project(input, projection); } NotifyIfChanged(expression, result); return(result); }
public override DbExpression Visit(DbSortExpression expression) { EntityUtil.CheckArgumentNull(expression, "expression"); DbExpression result = expression; DbExpressionBinding newInput = this.VisitExpressionBindingEnterScope(expression.Input); IList <DbSortClause> newSortOrder = this.VisitSortOrder(expression.SortOrder); this.ExitScope(); if (!object.ReferenceEquals(expression.Input, newInput) || !object.ReferenceEquals(expression.SortOrder, newSortOrder)) { result = CqtBuilder.Sort(newInput, newSortOrder); } NotifyIfChanged(expression, result); return(result); }
// Utility translator method for lambda expressions. Given a lambda expression and its translated // inputs, translates the lambda expression, assuming the input is a collection private DbExpression TranslateLambda(LambdaExpression lambda, DbExpression input, string bindingName, out DbExpressionBinding binding) { input = NormalizeSetSource(input); // create binding context for this lambda expression binding = input.BindAs(bindingName); return TranslateLambda(lambda, binding.Variable); }
/// <summary> /// Dumps a DbExpressionBinding with the specified decoration /// </summary> /// <param name="binding">The DbExpressionBinding to dump</param> /// <param name="name">The decorating block name</param> internal void Dump(DbExpressionBinding binding, string name) { Begin(name); Dump(binding); End(name); }
internal ProjectionCollapser(Dictionary<string, DbExpression> varRefMemberBindings, DbExpressionBinding outerBinding) : base() { m_varRefMemberBindings = varRefMemberBindings; m_outerBinding = outerBinding; }
protected virtual void VisitExpressionBindingPost(DbExpressionBinding binding) { }
internal DbExpression Filter(DbExpressionBinding input, DbExpression predicate) { OrderByLifterBase lifter = GetLifter(input.Expression); return lifter.Filter(input.Filter(predicate)); }
/// <summary> /// Helper method for <see cref="TransformIntersectOrExcept(DbExpression left, DbExpression right, DbExpressionKind expressionKind, IList<DbPropertyExpression> sortExpressionsOverLeft, string sortExpressionsBindingVariableName)"/> /// Creates a <see cref="DbProjectExpression"/> over the given inputBinding that projects out the given flattenedProperties. /// and updates the flattenedProperties to be over the newly created project. /// </summary> /// <param name="inputBinding"></param> /// <param name="flattenedProperties"></param> /// <returns>An <see cref="DbExpressionBinding"/> over the newly created <see cref="DbProjectExpression"/></returns> private static DbExpressionBinding CapWithProject(DbExpressionBinding inputBinding, IList<DbPropertyExpression> flattenedProperties) { var projectColumns = new List<KeyValuePair<string, DbExpression>>(flattenedProperties.Count); //List of all the columnNames used in the projection. var columnNames = new Dictionary<string, int>(flattenedProperties.Count); foreach (var pe in flattenedProperties) { //There may be conflicting property names, thus we may need to rename. var name = pe.Property.Name; int i; if (columnNames.TryGetValue(name, out i)) { string newName; do { ++i; newName = name + i.ToString(CultureInfo.InvariantCulture); } while (columnNames.ContainsKey(newName)); columnNames[name] = i; name = newName; } // Add this column name to list of known names so that there are no subsequent // collisions columnNames[name] = 0; projectColumns.Add(new KeyValuePair<string, DbExpression>(name, pe)); } //Build the project DbExpression rowExpr = DbExpressionBuilder.NewRow(projectColumns); var projectExpression = inputBinding.Project(rowExpr); //Create the new inputBinding var resultBinding = projectExpression.Bind(); //Create the list of flattenedProperties over the new project flattenedProperties.Clear(); var rowExprType = (RowType)rowExpr.ResultType.EdmType; foreach (var column in projectColumns) { var prop = rowExprType.Properties[column.Key]; flattenedProperties.Add(resultBinding.Variable.Property(prop)); } return resultBinding; }
internal DbDeleteCommandTree(MetadataWorkspace metadata, DataSpace dataSpace, DbExpressionBinding target, DbExpression predicate) : base(metadata, dataSpace, target) { EntityUtil.CheckArgumentNull(predicate, "predicate"); this._predicate = predicate; }
/// <summary> /// Convenience method to visit the specified <see cref="DbExpressionBinding"/>. /// </summary> /// <param name="binding">The DbExpressionBinding to visit.</param> /// <exception cref="ArgumentNullException"><paramref name="binding"/> is null</exception> protected virtual void VisitExpressionBindingPre(DbExpressionBinding binding) { EntityUtil.CheckArgumentNull(binding, "binding"); VisitExpression(binding.Expression); }
internal DbUpdateCommandTree(MetadataWorkspace metadata, DataSpace dataSpace, DbExpressionBinding target, DbExpression predicate, ReadOnlyModificationClauses setClauses, DbExpression returning) : base(metadata, dataSpace, target) { EntityUtil.CheckArgumentNull(predicate, "predicate"); EntityUtil.CheckArgumentNull(setClauses, "setClauses"); // returning is allowed to be null this._predicate = predicate; this._setClauses = setClauses; this._returning = returning; }
private DbExpression Filter(DbExpressionBinding input, DbExpression predicate) { DbExpression retExpr = _orderByLifter.Filter(input, predicate); ApplySpanMapping(input.Expression, retExpr); return retExpr; }
private DbExpression Project(DbExpressionBinding input, DbExpression projection) { DbExpression retExpr = _orderByLifter.Project(input, projection); // For identity projection only, the Span is preserved if (projection.ExpressionKind == DbExpressionKind.VariableReference && ((DbVariableReferenceExpression)projection).VariableName.Equals(input.VariableName, StringComparison.Ordinal)) { ApplySpanMapping(input.Expression, retExpr); } return retExpr; }
private DbSortExpression Sort(DbExpressionBinding input, IList<DbSortClause> keys) { DbSortExpression retExpr = input.Sort(keys); ApplySpanMapping(input.Expression, retExpr); return retExpr; }
private DbExpression Skip(DbExpressionBinding input, DbExpression skipCount) { DbExpression retExpr = _orderByLifter.Skip(input, skipCount); ApplySpanMapping(input.Expression, retExpr); return retExpr; }
/// <summary> /// Dumps a DbExpressionBinding including its VariableName and DbExpression /// </summary> /// <param name="binding">The DbExpressionBinding to dump</param> internal void Dump(DbExpressionBinding binding) { Begin("DbExpressionBinding", "VariableName", binding.VariableName); Begin("Expression"); Dump(binding.Expression); End("Expression"); End("DbExpressionBinding"); }
/// <summary> /// Convenience method for post-processing after a DbExpressionBinding has been visited. /// </summary> /// <param name="binding">The previously visited DbExpressionBinding.</param> protected virtual void VisitExpressionBindingPost(DbExpressionBinding binding) { }
/// <summary> /// Convenience method to visit the specified <see cref="DbExpressionBinding"/>. /// </summary> /// <param name="binding">The DbExpressionBinding to visit.</param> /// <exception cref="ArgumentNullException"><paramref name="binding"/> is null</exception> protected virtual void VisitExpressionBindingPre(DbExpressionBinding binding) { ADP1.CheckArgumentNull(binding, "binding"); VisitExpression(binding.Expression); }
/// <summary> /// Determines column/value used to set values for a row. /// </summary> /// <remarks> /// The following columns are not included in the result: /// <list> /// <item>Keys in non-insert operations (keys are only set for inserts).</item> /// <item>Values flagged 'preserve' (these are values the propagator claims are untouched).</item> /// <item>Server generated values.</item> /// </list> /// </remarks> /// <param name="target">Expression binding representing the table.</param> /// <param name="row">Row containing values to set.</param> /// <param name="processor">Context for table.</param> /// <param name="insertMode">Determines whether key columns and 'preserve' columns are /// omitted from the list.</param> /// <param name="outputIdentifiers">Dictionary listing server generated identifiers.</param> /// <param name="returning">DbExpression describing result projection for server generated values.</param> /// <param name="rowMustBeTouched">Indicates whether the row must be touched /// because it produces a value (e.g. computed)</param> /// <returns>Column value pairs.</returns> private IEnumerable<DbModificationClause> BuildSetClauses(DbExpressionBinding target, PropagatorResult row, PropagatorResult originalRow, TableChangeProcessor processor, bool insertMode, out Dictionary<int, string> outputIdentifiers, out DbExpression returning, ref bool rowMustBeTouched) { Dictionary<EdmProperty, PropagatorResult> setClauses = new Dictionary<EdmProperty, PropagatorResult>(); List<KeyValuePair<string, DbExpression>> returningArguments = new List<KeyValuePair<string, DbExpression>>(); outputIdentifiers = new Dictionary<int, string>(); // Determine which flags indicate a property should be omitted from the set list. PropagatorFlags omitMask = insertMode ? PropagatorFlags.NoFlags : PropagatorFlags.Preserve | PropagatorFlags.Unknown; for (int propertyOrdinal = 0; propertyOrdinal < processor.Table.ElementType.Properties.Count; propertyOrdinal++) { EdmProperty property = processor.Table.ElementType.Properties[propertyOrdinal]; // Type members and result values are ordinally aligned PropagatorResult propertyResult = row.GetMemberValue(propertyOrdinal); if (PropagatorResult.NullIdentifier != propertyResult.Identifier) { // retrieve principal value propertyResult = propertyResult.ReplicateResultWithNewValue( m_translator.KeyManager.GetPrincipalValue(propertyResult)); } bool omitFromSetList = false; Debug.Assert(propertyResult.IsSimple); // Determine if this is a key value bool isKey = false; for (int i = 0; i < processor.KeyOrdinals.Length; i++) { if (processor.KeyOrdinals[i] == propertyOrdinal) { isKey = true; break; } } // check if this value should be omitted PropagatorFlags flags = PropagatorFlags.NoFlags; if (!insertMode && isKey) { // Keys are only set for inserts omitFromSetList = true; } else { // See if this value has been marked up with some context. If so, add the flag information // from the markup. Markup includes information about whether the property is a concurrency value, // whether it is known (it may be a property that is preserved across an update for instance) flags |= propertyResult.PropagatorFlags; } // Determine if this value is server-generated StoreGeneratedPattern genPattern = MetadataHelper.GetStoreGeneratedPattern(property); bool isServerGen = genPattern == StoreGeneratedPattern.Computed || (insertMode && genPattern == StoreGeneratedPattern.Identity); if (isServerGen) { DbPropertyExpression propertyExpression = target.Variable.Property(property); returningArguments.Add(new KeyValuePair<string, DbExpression>(property.Name, propertyExpression)); // check if this is a server generated identifier int identifier = propertyResult.Identifier; if (PropagatorResult.NullIdentifier != identifier) { if (m_translator.KeyManager.HasPrincipals(identifier)) { throw EntityUtil.InvalidOperation(System.Data.Entity.Strings.Update_GeneratedDependent(property.Name)); } outputIdentifiers.Add(identifier, property.Name); // If this property maps an identifier (in the update pipeline) it may // also be a store key. If so, the pattern had better be "Identity" // since otherwise we're dealing with a mutable key. if (genPattern != StoreGeneratedPattern.Identity && processor.IsKeyProperty(propertyOrdinal)) { throw EntityUtil.NotSupported(System.Data.Entity.Strings.Update_NotSupportedComputedKeyColumn( EdmProviderManifest.StoreGeneratedPatternFacetName, XmlConstants.Computed, XmlConstants.Identity, property.Name, property.DeclaringType.FullName)); } } } if (PropagatorFlags.NoFlags != (flags & (omitMask))) { // column value matches "omit" pattern, therefore should not be set omitFromSetList = true; } else if (isServerGen) { // column value does not match "omit" pattern, but it is server generated // so it cannot be set omitFromSetList = true; // if the row has a modified value overridden by server gen, // it must still be touched in order to retrieve the value rowMustBeTouched = true; } // make the user is not updating an identity value if (!omitFromSetList && !insertMode && genPattern == StoreGeneratedPattern.Identity) { //throw the error only if the value actually changed Debug.Assert(originalRow != null, "Updated records should have a original row"); PropagatorResult originalPropertyResult = originalRow.GetMemberValue(propertyOrdinal); Debug.Assert(originalPropertyResult.IsSimple, "Server Gen property that is not primitive?"); Debug.Assert(propertyResult.IsSimple, "Server Gen property that is not primitive?"); if (!ByValueEqualityComparer.Default.Equals(originalPropertyResult.GetSimpleValue(), propertyResult.GetSimpleValue())) { throw EntityUtil.InvalidOperation(System.Data.Entity.Strings.Update_ModifyingIdentityColumn( XmlConstants.Identity, property.Name, property.DeclaringType.FullName)); } else { omitFromSetList = true; } } if (!omitFromSetList) { setClauses.Add(property, propertyResult); } } // Construct returning projection if (0 < returningArguments.Count) { returning = DbExpressionBuilder.NewRow(returningArguments); } else { returning = null; } // Construct clauses corresponding to the set clauses List<DbModificationClause> result = new List<DbModificationClause>(setClauses.Count); foreach (KeyValuePair<EdmProperty, PropagatorResult> setClause in setClauses) { EdmProperty property = setClause.Key; result.Add(new DbSetClause( GeneratePropertyExpression(target, setClause.Key), GenerateValueExpression(setClause.Key, setClause.Value))); } return result; }
internal DbExpression Project(DbExpressionBinding input, DbExpression projection) { OrderByLifterBase lifter = GetLifter(input.Expression); return lifter.Project(input.Project(projection)); }
/// <summary> /// Determines predicate used to identify a row in a table. /// </summary> /// <remarks> /// Columns are included in the list when: /// <list> /// <item>They are keys for the table</item> /// <item>They are concurrency values</item> /// </list> /// </remarks> /// <param name="target">Expression binding representing the table containing the row</param> /// <param name="referenceRow">Values for the row being located.</param> /// <param name="current">Values being updated (may be null).</param> /// <param name="processor">Context for the table containing the row.</param> /// <param name="rowMustBeTouched">Output parameter indicating whether a row must be touched /// (whether it's being modified or not) because it contains a concurrency value</param> /// <returns>Column/value pairs.</returns> private DbExpression BuildPredicate(DbExpressionBinding target, PropagatorResult referenceRow, PropagatorResult current, TableChangeProcessor processor, ref bool rowMustBeTouched) { Dictionary<EdmProperty, PropagatorResult> whereClauses = new Dictionary<EdmProperty, PropagatorResult>(); // add all concurrency tokens (note that keys are always concurrency tokens as well) int propertyOrdinal = 0; foreach (EdmProperty member in processor.Table.ElementType.Properties) { // members and result values are ordinally aligned PropagatorResult expectedValue = referenceRow.GetMemberValue(propertyOrdinal); PropagatorResult newValue = null == current ? null : current.GetMemberValue(propertyOrdinal); // check if the rowMustBeTouched value should be set to true (if it isn't already // true and we've come across a concurrency value) if (!rowMustBeTouched && (HasFlag(expectedValue, PropagatorFlags.ConcurrencyValue) || HasFlag(newValue, PropagatorFlags.ConcurrencyValue))) { rowMustBeTouched = true; } // determine if this is a concurrency value if (!whereClauses.ContainsKey(member) && // don't add to the set clause twice (HasFlag(expectedValue, PropagatorFlags.ConcurrencyValue | PropagatorFlags.Key) || HasFlag(newValue, PropagatorFlags.ConcurrencyValue | PropagatorFlags.Key))) // tagged as concurrency value { whereClauses.Add(member, expectedValue); } propertyOrdinal++; } // Build a binary AND expression tree from the clauses DbExpression predicate = null; foreach (KeyValuePair<EdmProperty, PropagatorResult> clause in whereClauses) { DbExpression clauseExpression = GenerateEqualityExpression(target, clause.Key, clause.Value); if (null == predicate) { predicate = clauseExpression; } else { predicate = predicate.And(clauseExpression); } } Debug.Assert(null != predicate, "some predicate term must exist"); return predicate; }
internal DbExpression Skip(DbExpressionBinding input, DbExpression skipCount) { OrderByLifterBase lifter = GetLifter(input.Expression); return lifter.Skip(skipCount); }
// Effects: given a "clause" in the form of a property/value pair, produces an equality expression. If the // value is null, creates an IsNull expression // Requires: all arguments are set private DbExpression GenerateEqualityExpression(DbExpressionBinding target, EdmProperty property, PropagatorResult value) { Debug.Assert(null != target && null != property && null != value); DbExpression propertyExpression = GeneratePropertyExpression(target, property); DbExpression valueExpression = GenerateValueExpression(property, value); if (valueExpression.ExpressionKind == DbExpressionKind.Null) { return propertyExpression.IsNull(); } return propertyExpression.Equal(valueExpression); }
/// <summary> /// Convenience method to visit the specified <see cref="DbExpressionBinding"/>. /// </summary> /// <param name="binding">The DbExpressionBinding to visit.</param> /// <exception cref="ArgumentNullException"><paramref name="binding"/> is null</exception> protected virtual void VisitExpressionBindingPre(DbExpressionBinding binding) { //Contract.Requires(binding != null); VisitExpression(binding.Expression); }
// Effects: given a property, produces a property expression // Requires: all arguments are set private static DbExpression GeneratePropertyExpression(DbExpressionBinding target, EdmProperty property) { Debug.Assert(null != target && null != property); return target.Variable.Property(property); }
private SqlFragment HandleJoinExpression(DbExpressionBinding left, DbExpressionBinding right, DbExpressionKind joinType, DbExpression joinCondition) { JoinFragment join = new JoinFragment(); join.JoinType = Metadata.GetOperator(joinType); join.Left = VisitInputExpression(left.Expression, left.VariableName, left.VariableType); WrapJoinInputIfNecessary(join.Left, false); join.Right = VisitInputExpression(right.Expression, right.VariableName, right.VariableType); WrapJoinInputIfNecessary(join.Right, true); // now handle the ON case if (joinCondition != null) join.Condition = joinCondition.Accept(this); return join; }
private void VisitBinding(DbExpressionBinding binding) { _key.Append("BV"); VisitVariableName(binding.VariableName); _key.Append("=("); binding.Expression.Accept(this); _key.Append(')'); }
protected virtual void VisitExpressionBindingPre(DbExpressionBinding binding) { if (binding == null) throw new ArgumentException("binding"); VisitExpression(binding.Expression); }
internal DbInsertCommandTree(MetadataWorkspace metadata, DataSpace dataSpace, DbExpressionBinding target, ReadOnlyModificationClauses setClauses, DbExpression returning) : base(metadata, dataSpace, target) { EntityUtil.CheckArgumentNull(setClauses, "setClauses"); // returning may be null this._setClauses = setClauses; this._returning = returning; }