public void FetchOnWithSecondGenericType() { var s = new DefaultSqlExpression <User>(Database, true); var joinexp = s.On <CustomerUser>((x, y) => x.Name == y.CustomerName); Assert.AreEqual(joinexp, "([U].[Name] = [CU].[CustomerName])"); }
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); } }
public void WhereExpressionWithNullableEnum() { var sqlExpression = new DefaultSqlExpression <UserWithNullableId>(Database); sqlExpression.Where(x => x.NameEnum == NameEnum.Bobby); Assert.AreEqual(sqlExpression.Context.Params[0], "Bobby"); }
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 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); }
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); }
public void SelectStatementDoesNotRenderPropertyNameAsAlias() { var sqlExpression = new DefaultSqlExpression <UserDecorated>(Database); sqlExpression.Select(x => new { x.IsMale, x.Name }); var selectStatement = sqlExpression.Context.ToSelectStatement(); Assert.AreEqual("SELECT [is_male], [Name] \nFROM [Users] UD", selectStatement); }
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); }
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); }
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); }
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); }
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); } }
//[Test, NUnit.Framework.Ignore("Not Supported For Now")] public void FetchOnWithSecondGenericType() { var s = new DefaultSqlExpression <CustomerUserJoin>(Database, true); var joinexp = s.On <CustomerUser>((x, y) => x.Name == y.CustomerName); string expected = string.Format("({0}.{1} = {2}.{3})", TestDatabase.DbType.EscapeTableName("CUJ"), TestDatabase.DbType.EscapeTableName("Name"), TestDatabase.DbType.EscapeTableName("CU"), TestDatabase.DbType.EscapeTableName("CustomerName")); Assert.AreEqual(expected, joinexp); }
public void FetchOnWithSecondGenericType() { var s = new DefaultSqlExpression<User>(Database, true); var joinexp = s.On<CustomerUser>((x, y) => x.Name == y.CustomerName); string expected = string.Format("({0}.{1} = {2}.{3})", TestDatabase.DbType.EscapeTableName("U"), TestDatabase.DbType.EscapeTableName("Name"), TestDatabase.DbType.EscapeTableName("CU"), TestDatabase.DbType.EscapeTableName("CustomerName")); Assert.AreEqual(expected, joinexp); }
public void SelectStatementDoesNotRenderPropertyNameAsAlias() { var sqlExpression = new DefaultSqlExpression <UserDecorated>(Database); sqlExpression.Select(x => new { x.IsMale, x.Name }); var selectStatement = sqlExpression.Context.ToSelectStatement(); string expected = string.Format("SELECT {0}, {1} \nFROM {2}", TestDatabase.DbType.EscapeSqlIdentifier("is_male"), TestDatabase.DbType.EscapeSqlIdentifier("Name"), TestDatabase.DbType.EscapeTableName("Users")); Assert.AreEqual(expected, selectStatement); }
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 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"); }
public void SelectStatementDoesNotRenderPropertyNameAsAlias() { var sqlExpression = new DefaultSqlExpression<UserDecorated>(Database); sqlExpression.Select(x => new {x.IsMale, x.Name}); var selectStatement = sqlExpression.Context.ToSelectStatement(); string expected = string.Format("SELECT {0}, {1} \nFROM {2}", TestDatabase.DbType.EscapeSqlIdentifier("is_male"), TestDatabase.DbType.EscapeSqlIdentifier("Name"), TestDatabase.DbType.EscapeTableName("Users")); Assert.AreEqual(expected, selectStatement); }
public void SelectStatementDoesNotRenderPropertyNameAsAlias() { var sqlExpression = new DefaultSqlExpression<UserDecorated>(Database); sqlExpression.Select(x => new {x.IsMale, x.Name}); var selectStatement = sqlExpression.Context.ToSelectStatement(); Assert.AreEqual("SELECT [is_male],[Name] \nFROM [Users]", selectStatement); }