Exemple #1
0
        private void ThrowExceptionForParameterPair(string exceptionMessage, ParameterFoundAtLevel parameter1, ParameterFoundAtLevel parameter2)
        {
            var concrete1 = parameter1.Parameter as IMapsDirectlyToDatabaseTable;
            var concrete2 = parameter2.Parameter as IMapsDirectlyToDatabaseTable;

            List <IMapsDirectlyToDatabaseTable> concreteObjects = new List <IMapsDirectlyToDatabaseTable>();

            string desc1 = "(Type:" + parameter1.Parameter.GetType();
            string desc2 = "(Type:" + parameter2.Parameter.GetType();


            if (concrete1 != null)
            {
                concreteObjects.Add(concrete1);
                desc1 += " ID:" + concrete1.ID;
            }

            if (concrete2 != null)
            {
                concreteObjects.Add(concrete2);
                desc2 += " ID:" + concrete2.ID;
            }

            desc1 += ")";
            desc2 += ")";

            exceptionMessage += ".  Problem objects were " + parameter1 + desc1 + " and " + parameter2 + " " + desc2;

            throw new QueryBuildingException(exceptionMessage, concreteObjects);
        }
Exemple #2
0
        private void AddParameterToCollection(ParameterFoundAtLevel toAdd, List <ParameterFoundAtLevel> existingParameters)
        {
            //see if parameter if we already have one with the same name
            var duplicate = existingParameters.FirstOrDefault(p => p.Parameter.ParameterName.Equals(toAdd.Parameter.ParameterName, StringComparison.InvariantCultureIgnoreCase));

            if (duplicate != null)
            {
                //deal with duplicate paramater naming e.g. @startDate BUT: declared with 2 different types
                if (
                    !toAdd.Parameter.ParameterSQL.Trim()
                    .Equals(duplicate.Parameter.ParameterSQL.Trim(), StringComparison.CurrentCultureIgnoreCase))
                {
                    //to lower them so that we don't complain about 'AS VARCHAR(50)' vs 'as varchar(50)'
                    ThrowExceptionForParameterPair("Found multiple parameters called " + toAdd.Parameter + " but with differing SQL:" + toAdd.Parameter.ParameterSQL + " vs " + duplicate.Parameter.ParameterSQL, toAdd, duplicate);
                }


                //if values differ!
                if (!string.Equals((duplicate.Parameter.Value ?? "").Trim(), (toAdd.Parameter.Value ?? "").Trim(), StringComparison.CurrentCultureIgnoreCase))
                {
                    //if the duplicate (already existing) parameter is of a lower level then it can be discarded because it didn't have a dodgy type mismatch etc (see ThrowIfUnsuitable above)
                    if (duplicate.Level < toAdd.Level)
                    {
                        existingParameters.Remove(duplicate);
                        existingParameters.Add(toAdd);
                    }
                    else
                    {
                        ThrowExceptionForParameterPair("Found 2+ parameters with the name " + toAdd +
                                                       " but differing Values of \"" + toAdd.Parameter.Value + "\" and \"" +
                                                       duplicate.Parameter.Value + "\"", toAdd, duplicate);
                    }
                }
                //if we get here then its a duplicate but it is an exact duplicate so dont worry
            }
            else
            {
                existingParameters.Add(toAdd); //its not a duplicate so add it to the list of RequiredParameters
            }
        }