// effects: try to find setter expression for the given member // requires: command tree must be an insert or update tree (since other DML trees hnabve private static bool TryGetSetterExpression( DbModificationCommandTree tree, EdmMember member, ModificationOperator op, out DbSetClause setter) { Debug.Assert(op == ModificationOperator.Insert || op == ModificationOperator.Update, "only inserts and updates have setters"); IEnumerable<DbModificationClause> clauses; if (ModificationOperator.Insert == op) { clauses = ((DbInsertCommandTree)tree).SetClauses; } else { clauses = ((DbUpdateCommandTree)tree).SetClauses; } foreach (DbSetClause setClause in clauses) { // check if this is the correct setter if (((DbPropertyExpression)setClause.Property).Property.EdmEquals(member)) { setter = setClause; return true; } } // no match found setter = null; return false; }
/// <summary> /// Gets DB command definition encapsulating store logic for this command. /// </summary> protected virtual DbCommand CreateCommand(Dictionary<int, object> identifierValues) { var commandTree = _modificationCommandTree; // check if any server gen identifiers need to be set if (null != _inputIdentifiers) { var modifiedClauses = new Dictionary<DbSetClause, DbSetClause>(); for (var idx = 0; idx < _inputIdentifiers.Count; idx++) { var inputIdentifier = _inputIdentifiers[idx]; object value; if (identifierValues.TryGetValue(inputIdentifier.Key, out value)) { // reset the value of the identifier var newClause = new DbSetClause(inputIdentifier.Value.Property, DbExpressionBuilder.Constant(value)); modifiedClauses[inputIdentifier.Value] = newClause; _inputIdentifiers[idx] = new KeyValuePair<int, DbSetClause>(inputIdentifier.Key, newClause); } } commandTree = RebuildCommandTree(commandTree, modifiedClauses); } return Translator.CreateCommand(commandTree); }
protected virtual void VisitSetClause(DbSetClause setClause) { Contract.Requires(setClause != null); VisitExpression(setClause.Property); VisitExpression(setClause.Value); }
/// <summary>Implements the visitor pattern for the set clause.</summary> /// <param name="setClause">The set clause.</param> protected virtual void VisitSetClause(DbSetClause setClause) { Check.NotNull(setClause, "setClause"); VisitExpression(setClause.Property); VisitExpression(setClause.Value); }
/// <summary>Implements the visitor pattern for the set clause.</summary> /// <param name="setClause">The set clause.</param> protected virtual void VisitSetClause(DbSetClause setClause) { Check.NotNull <DbSetClause>(setClause, nameof(setClause)); this.VisitExpression(setClause.Property); this.VisitExpression(setClause.Value); }