Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RawSql.Insert cannot be used as entire Where clause or Set clause in UpdateDataExpression/DeleteDataExpression #1827

Open
jzabroski opened this issue Jun 18, 2024 · 0 comments

Comments

@jzabroski
Copy link
Collaborator

Describe the bug
RawSql.Insert cannot be used as entire Where clause or Set clause in UpdateDataExpression/DeleteDataExpression

To Reproduce

    [Migration(202406181031, "Testing RawSql.Insert behavior")]
    public class TestMigration : ForwardOnlyMigration
    {
        public override void Up()
        {
            Update.Table("Foo").InSchema("dbo")
                .Set(RawSql.Insert("Baz = CASE WHEN Bar = 1 THEN 2 ELSE 0 END"))
                .Where(RawSql.Insert("Baz IS NULL"));
        }
    }

generates the following invalid SQL expression:

UPDATE [dbo].[Foo] SET [Value] = N'Baz = CASE WHEN Bar = 1 THEN 2 ELSE 0 END' WHERE [Value] = N'Baz IS NULL'

Expected behavior
RawSql should be... raw sql :)

Information (please complete the following information):

  • FluentMigrator version 5.2.0

Additional context
Workaround is to use Execute.Sql syntax instead:

    [Migration(202406181031, "Testing RawSql.Insert behavior")]
    public class TestMigration : ForwardOnlyMigration
    {
        public override void Up()
        {
            Execute.Sql(@"UPDATE dbo.Foo
SET Baz = CASE WHEN Bar = 1 THEN 2 ELSE 0 END
WHERE Baz IS NULL");
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant