예제 #1
0
        public static SqlConnection GetSqlConnection(ObjectQuery query)
        {
            if (query == null)
            {
                throw new System.ArgumentException("Parameter cannot be null", nameof(query));
            }

            return(new SqlConnection(QueryExtension.GetConnectionString(query)));
        }
예제 #2
0
        /// <summary>
        /// Use ObjectQuery to get SqlConnection and SqlCommand.
        /// </summary>
        public static SqlCommand GetSqlCommand(ObjectQuery query, SqlConnection connection)
        {
            if (query == null)
            {
                throw new System.ArgumentException("Parameter cannot be null", nameof(query));
            }

            SqlCommand command = new SqlCommand(QueryExtension.GetSqlString(query), connection);

            // Add all the paramters used in query.
            foreach (ObjectParameter parameter in query.Parameters)
            {
                command.Parameters.AddWithValue(parameter.Name, parameter.Value);
            }

            return(command);
        }