示例#1
0
        // <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));
        }
示例#2
0
        /// <summary>
        /// Gets DB command definition encapsulating store logic for this command.
        /// </summary>
        private DbCommand CreateCommand(UpdateTranslator translator, Dictionary <int, object> identifierValues)
        {
            DbModificationCommandTree commandTree = m_modificationCommandTree;

            // check if any server gen identifiers need to be set
            if (null != m_inputIdentifiers)
            {
                Dictionary <DbSetClause, DbSetClause> modifiedClauses = new Dictionary <DbSetClause, DbSetClause>();
                for (int idx = 0; idx < m_inputIdentifiers.Count; idx++)
                {
                    KeyValuePair <int, DbSetClause> inputIdentifier = m_inputIdentifiers[idx];

                    object value;
                    if (identifierValues.TryGetValue(inputIdentifier.Key, out value))
                    {
                        // reset the value of the identifier
                        DbSetClause newClause = new DbSetClause(inputIdentifier.Value.Property, DbExpressionBuilder.Constant(value));
                        modifiedClauses[inputIdentifier.Value] = newClause;
                        m_inputIdentifiers[idx] = new KeyValuePair <int, DbSetClause>(inputIdentifier.Key, newClause);
                    }
                }
                commandTree = RebuildCommandTree(commandTree, modifiedClauses);
            }

            return(translator.CreateCommand(commandTree));
        }
示例#3
0
        private void AddOrReplaceClause(ICollection <DbModificationClause> clauses, DbSetClause clause)
        {
            var res = clauses.FirstOrDefault(c => ((DbPropertyExpression)((DbSetClause)c).Property).Property.Name == ((DbPropertyExpression)clause.Property).Property.Name);

            if (res != null)
            {
                clauses.Remove(res);
            }
            clauses.Add(clause);
        }
示例#4
0
        private DbSetClause GetInsertSetClause(string column, DbExpression newValueToSetToDb, DbInsertCommandTree insertCommand)
        {
            // Create the variable reference in order to create the property
            DbVariableReferenceExpression variableReference = DbExpressionBuilder.Variable(insertCommand.Target.VariableType,
                                                                                           insertCommand.Target.VariableName);
            // Create the property to which will assign the correct value
            DbPropertyExpression tenantProperty = DbExpressionBuilder.Property(variableReference, column);
            // Create the set clause, object representation of sql insert command
            DbSetClause newSetClause = DbExpressionBuilder.SetClause(tenantProperty, newValueToSetToDb);

            return(newSetClause);
        }
示例#5
0
 private static bool TryGetSetterExpression(
     DbModificationCommandTree tree,
     EdmMember member,
     ModificationOperator op,
     out DbSetClause setter)
 {
     foreach (DbSetClause dbSetClause in ModificationOperator.Insert != op ? (IEnumerable <DbModificationClause>)((DbUpdateCommandTree)tree).SetClauses : (IEnumerable <DbModificationClause>)((DbInsertCommandTree)tree).SetClauses)
     {
         if (((DbPropertyExpression)dbSetClause.Property).Property.EdmEquals((MetadataItem)member))
         {
             setter = dbSetClause;
             return(true);
         }
     }
     setter = (DbSetClause)null;
     return(false);
 }
示例#6
0
        protected virtual DbCommand CreateCommand(Dictionary <int, object> identifierValues)
        {
            DbModificationCommandTree modificationCommandTree = this._modificationCommandTree;

            if (this._inputIdentifiers != null)
            {
                Dictionary <DbSetClause, DbSetClause> clauseMappings = new Dictionary <DbSetClause, DbSetClause>();
                for (int index = 0; index < this._inputIdentifiers.Count; ++index)
                {
                    KeyValuePair <int, DbSetClause> inputIdentifier = this._inputIdentifiers[index];
                    object obj;
                    if (identifierValues.TryGetValue(inputIdentifier.Key, out obj))
                    {
                        DbSetClause dbSetClause = new DbSetClause(inputIdentifier.Value.Property, (DbExpression)DbExpressionBuilder.Constant(obj));
                        clauseMappings[inputIdentifier.Value] = dbSetClause;
                        this._inputIdentifiers[index]         = new KeyValuePair <int, DbSetClause>(inputIdentifier.Key, dbSetClause);
                    }
                }
                modificationCommandTree = DynamicUpdateCommand.RebuildCommandTree(modificationCommandTree, clauseMappings);
            }
            return(this.Translator.CreateCommand(modificationCommandTree));
        }
示例#7
0
        // 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);
        }