Inheritance: IWhereClause
Exemple #1
0
        public void Clone()
        {
            var item = new WhereItem("field1", "a string");
            var clone = item.Clone();

            Assert.AreEqual(item, clone);
            clone.Value = "something-else";
            Assert.AreNotEqual(item, clone);
            clone.Value = "a string";
            Assert.AreEqual(item, clone);

            var parm = new QueryParameter("someparm", "testvalue");
            var item2 = new WhereString("field2=@someparm or field3='value'", parm);

            var clause = new WhereClause(JoinType.And,item, item2);
            var clone2 = clause.Clone();
            Assert.AreEqual(clause, clone2);
            parm.Value = "testvalue2";
            Assert.AreNotEqual(clause, clone2);
            parm.Value = "testvalue";
            Assert.AreEqual(clause, clone2);

            item.Value = "n";
            Assert.AreNotEqual(clause, clone2);
            item.Value = "a string";
            Assert.AreEqual(clause, clone2);
        }
Exemple #2
0
        public void Create()
        {
            var item1 = new WhereItem("field1",123);

            var parm = new QueryParameter("someparm","testvalue");
            var item2 = new WhereString("field2=@someparm",parm);
            var clause = new WhereClause(JoinType.And, item1, item2);

            Assert.AreEqual("field1=@field1 AND (field2=@someparm)", clause.GetSql());

            Assert.AreEqual(2, clause.Parameters.Count());
        }
Exemple #3
0
        public void Combine()
        {
            var item1 = new WhereItem("field1", 123);

            var parm = new QueryParameter("someparm", "testvalue");
            var item2 = new WhereString("field2=@someparm or field3='value'", parm);
            var item3 = new WhereItem("field4", 123,parameterize:false);

            var clause = new WhereClause(JoinType.And, item1, item2);

            Assert.AreEqual("field1=@field1 AND (field2=@someparm or field3='value')", clause.GetSql());
            var newClause = clause.Clone();
            newClause.Add(item3,JoinType.Or);
            Assert.AreEqual("(field1=@field1 AND (field2=@someparm or field3='value')) OR field4=123", newClause.GetSql());

            Assert.AreEqual(2, newClause.Parameters.Count());
        }
Exemple #4
0
        /// <summary>
        /// Adds a condition to the "Where" property, and returns self for chainability
        /// </summary>
        /// <param name="condition"></param>
        /// <param name="conditionType"></param>
        /// <returns></returns>
        protected void MergeWhere(IWhere item, JoinType joinType)
        {
            if (ReferenceEquals(item, this))
            {
                throw new ArgumentException("You're trying to add a where clause to itself.");
            }

            if (JoinType == joinType || IsEmpty)
            {
                AddImpl(item);
            }
            else
            {
                    // currently just a single criterion
                var clause = new WhereClause(joinType, this.Clone(), item);
                _InnerList = clause.InnerList;
                JoinType = joinType;
            }
            Touch();
        }
Exemple #5
0
 public WhereClause Clone()
 {
     WhereClause clone = new WhereClause();
     clone.JoinType = JoinType;
     foreach (var item in InnerList)
     {
         clone.Add(item.Clone());
     }
     return clone;
 }
Exemple #6
0
        public void IsEmpty()
        {
            var item = new WhereClause();
            Assert.IsTrue(item.IsEmpty);

            item.Add(new WhereString("a=b"));
            Assert.IsFalse(item.IsEmpty);
        }