Beispiel #1
0
        /// <summary>
        /// Validates the entry of the mapping.
        /// </summary>
        /// <param name="command">The type of command this mapping is used to.</param>
        /// <param name="map">The mapping to be used before execution.</param>
        private void Validate(Command command, DataEntityMap map)
        {
            if (map == null)
            {
                throw new NullReferenceException("Map");
            }
            var error = false;

            switch (command)
            {
            case Command.InlineInsert:
            case Command.InlineMerge:
            case Command.InlineUpdate:
                error = map.CommandType == CommandType.StoredProcedure;
                break;

            case Command.BatchQuery:
            case Command.BulkInsert:
            case Command.Count:
            case Command.Delete:
            case Command.DeleteAll:
            case Command.Insert:
            case Command.Merge:
            case Command.Query:
            case Command.Truncate:
            case Command.Update:
                error = false;
                break;
            }
            if (error)
            {
                throw new InvalidOperationException($"The command type '{map.CommandType.ToString()}' is not yet supported for '{command.ToString()}'.");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Set a mapping for the current defined entity.
        /// </summary>
        /// <param name="command">The type of command this mapping is used to.</param>
        /// <param name="map">The mapping to be used before execution.</param>
        /// <returns>The current instance of <see cref="DataEntityMapItem"/> that holds the mapping.</returns>
        public DataEntityMapItem Set(Command command, DataEntityMap map)
        {
            // Validate
            Validate(command, map);

            // Check and Add
            if (m_cache.ContainsKey(command))
            {
                throw new DuplicateDataEntityMapException(command);
            }
            else
            {
                m_cache.Add(command, map);
            }

            // Return
            return(this);
        }