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))); }
/// <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); }