コード例 #1
0
        public void ModifyTest()
        {
            var tUser     = Tables.User();
            var tCustomer = Tables.Customer();

            IExpr e = Select(tUser.UserId, tUser.FirstName, tCustomer.CustomerId)
                      .From(tUser)
                      .InnerJoin(tCustomer, on: tCustomer.UserId == tUser.UserId & tUser.Version == 1)
                      .Where(tUser.UserId.In(1))
                      .Done();

            //Before
            Assert.AreEqual("SELECT [A0].[UserId],[A0].[FirstName],[A1].[CustomerId] " +
                            "FROM [dbo].[user] [A0] JOIN [dbo].[Customer] [A1] " +
                            "ON [A1].[UserId]=[A0].[UserId] AND [A0].[Version]=1 " +
                            "WHERE [A0].[UserId] IN(1)", e.ToSql());

            e = e.SyntaxTree()
                .Modify(subE =>
            {
                if (subE is ExprIn)
                {
                    return(null);
                }
                if (subE is ExprBooleanAnd and && and.Right is ExprBooleanEq eq && eq.Right is ExprInt32Literal)
                {
                    return(and.Left);
                }
                if (subE is ExprColumnName c && c.Name == "UserId")
                {
                    return(new ExprColumnName("UserNewId"));
                }
                return(subE);
            });

            //After
            Assert.AreEqual("SELECT [A0].[UserNewId],[A0].[FirstName],[A1].[CustomerId] " +
                            "FROM [dbo].[user] [A0] JOIN [dbo].[Customer] [A1] " +
                            "ON [A1].[UserNewId]=[A0].[UserNewId]", e.ToSql());
        }