public void WhereExpressionWithNullableEnumContains()
 {
     var sqlExpression = new DefaultSqlExpression<UserWithNullableId>(Database);
     sqlExpression.Where(x => new List<NameEnum?> { NameEnum.Bill, NameEnum.Bobby }.Contains(x.NameEnum));
     Assert.AreEqual(sqlExpression.Context.Params[0], "Bill");
     Assert.AreEqual(sqlExpression.Context.Params[1], "Bobby");
 }
Пример #2
0
        public void WhereExpressionWithNullableEnumAndValueIsNull()
        {
            var sqlExpression = new DefaultSqlExpression <UserWithNullableId>(Database);

            sqlExpression.Where(x => x.NameEnum == null);
            Assert.AreEqual(sqlExpression.Context.Params.Length, 0);
        }
Пример #3
0
        public void WhereExpressionWithNullableEnum()
        {
            var sqlExpression = new DefaultSqlExpression <UserWithNullableId>(Database);

            sqlExpression.Where(x => x.NameEnum == NameEnum.Bobby);
            Assert.AreEqual(sqlExpression.Context.Params[0], "Bobby");
        }
Пример #4
0
        public virtual int Update(Expression <Func <T, bool> > whereExpression, Func <T, T> funcUpdate)
        {
            using (var db = GetDatabase())
            {
                SqlExpression <T> express = new DefaultSqlExpression <T>(db);
                express      = express.Where(whereExpression);
                string where = express.Context.ToWhereStatement();
                var poco = db.SingleOrDefault <T>(where, express.Context.Params);
                if (poco == null)
                {
                    return(0);
                }

                var snapshot = db.StartSnapshot(poco);
                poco = funcUpdate(poco);
                //return db.Update(poco, columns: snapshot.UpdatedColumns().ToArray());

                var columns = snapshot.UpdatedColumns().ToArray();
                var result  = db.Update(poco, columns: columns);
                if (result == 0 && columns.Length == 0)
                {
                    return(1); // 缓存中的数据和要更新的数据对应的字段值相等
                }
                return(result);
            }
        }
Пример #5
0
 public void NullableExpressionNotEqualsNull_ReturnsIsNotNull()
 {
     var sqlExpression = new DefaultSqlExpression<NullableProperty>(Database);
     sqlExpression.Where(x => x.Age != null);
     var whereStatement = sqlExpression.Context.ToWhereStatement();
     string expected = string.Format("WHERE ({0} is not null)", escapedAgeIdentifier);
     Assert.AreEqual(expected, whereStatement);
 }
Пример #6
0
 public void NullableExpressionHasValueWithAnotherExpression_ReturnsIsNotNull()
 {
     var sqlExpression = new DefaultSqlExpression<NullableProperty>(Database);
     sqlExpression.Where(x => x.Age.HasValue && x.Age > 2);
     var whereStatement = sqlExpression.Context.ToWhereStatement();
     string expected = string.Format("WHERE (({0} is not null) AND ([Age] > @0))", escapedAgeIdentifier);
     Assert.AreEqual(expected, whereStatement);
 }
Пример #7
0
        public void NullableExpressionNotEqualsNull_ReturnsIsNotNull()
        {
            var sqlExpression = new DefaultSqlExpression <NullableProperty>(Database);

            sqlExpression.Where(x => x.Age != null);
            var whereStatement = sqlExpression.Context.ToWhereStatement();

            Assert.AreEqual("WHERE ([Age] is not null)", whereStatement);
        }
Пример #8
0
        public void NullableExpressionHasValueEqualFalse_ReturnsIsNull()
        {
            var sqlExpression = new DefaultSqlExpression <NullableProperty>(Database);

            sqlExpression.Where(x => x.Age.HasValue == false);
            var whereStatement = sqlExpression.Context.ToWhereStatement();

            Assert.AreEqual("WHERE ([Age] is null)", whereStatement);
        }
Пример #9
0
        public void NullableExpressionNotEqualsNull_ReturnsIsNotNull()
        {
            var sqlExpression = new DefaultSqlExpression <NullableProperty>(Database);

            sqlExpression.Where(x => x.Age != null);
            var    whereStatement = sqlExpression.Context.ToWhereStatement();
            string expected       = string.Format("WHERE ({0} is not null)", escapedAgeIdentifier);

            Assert.AreEqual(expected, whereStatement);
        }
Пример #10
0
        public void ExpressionWithNullableExpressionNotHasValue_ReturnsNotIsNotNull()
        {
            var sqlExpression = new DefaultSqlExpression <NullableProperty>(Database);

            sqlExpression.Where(x => x.Age > 2 && x.Age.HasValue);
            var    whereStatement = sqlExpression.Context.ToWhereStatement();
            string expected       = string.Format("WHERE (([Age] > @0) AND ({0} is not null))", escapedAgeIdentifier);

            Assert.AreEqual(expected, whereStatement);
        }
Пример #11
0
 public virtual T SingleOrDefault(Expression <Func <T, bool> > whereExpression)
 {
     using (var db = GetDatabase())
     {
         SqlExpression <T> express = new DefaultSqlExpression <T>(db);
         express      = express.Where(whereExpression);
         string where = express.Context.ToWhereStatement();
         var poco = db.FirstOrDefault <T>(where, express.Context.Params);
         return(poco);
     }
 }
Пример #12
0
 public virtual int Delete(Expression <Func <T, bool> > whereExpression)
 {
     using (var db = GetDatabase())
     {
         /**
          *生成对应的where sql
          */
         SqlExpression <T> express = new DefaultSqlExpression <T>(db);
         express      = express.Where(whereExpression);
         string where = express.Context.ToWhereStatement();
         if (where.StartsWith("WHERE"))
         {
             where = where.Remove(0, 5);
         }
         return(db.DeleteWhere <T>(where, express.Context.Params));
     }
 }
 public void WhereExpressionWithNullableEnumContains()
 {
     var sqlExpression = new DefaultSqlExpression<UserWithNullableId>(Database);
     sqlExpression.Where(x => new List<NameEnum?> { NameEnum.Bill, NameEnum.Bobby }.Contains(x.NameEnum));
     Assert.AreEqual(sqlExpression.Context.Params[0], "Bill");
     Assert.AreEqual(sqlExpression.Context.Params[1], "Bobby");
 }
 public void WhereExpressionWithNullableEnumAndValueIsNull()
 {
     var sqlExpression = new DefaultSqlExpression<UserWithNullableId>(Database);
     sqlExpression.Where(x => x.NameEnum == null);
     Assert.AreEqual(sqlExpression.Context.Params.Length, 0);
 }
 public void WhereExpressionWithNullableEnum()
 {
     var sqlExpression = new DefaultSqlExpression<UserWithNullableId>(Database);
     sqlExpression.Where(x => x.NameEnum == NameEnum.Bobby);
     Assert.AreEqual(sqlExpression.Context.Params[0], "Bobby");
 }