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

InsertOrUpdate Support #93

Closed
Sicos1977 opened this issue Jun 25, 2018 · 8 comments
Closed

InsertOrUpdate Support #93

Sicos1977 opened this issue Jun 25, 2018 · 8 comments

Comments

@Sicos1977
Copy link

Sicos1977 commented Jun 25, 2018

Hi,

Is it possible to do something like this with sqlKata?

IF EXISTS
(
    SELECT  1
    FROM    [Example]
    WHERE   Id = @Id
)
BEGIN

    UPDATE  [Example]
    SET     [ChangedDate] = GETDATE(),
            [Example1]    = @Example1
    WHERE   [Id]          = @Id

END
ELSE
BEGIN

    INSERT INTO [Example]
    (
        [ChangedDate],
        [Example1],
    )
    Values
    (
        GETDATE(),
        @Example1
    )

END
@Sicos1977
Copy link
Author

I like your project. I cloned it and doing some code cleanup and adding comment.

@ahmad-moussawi
Copy link
Contributor

ahmad-moussawi commented Jun 26, 2018

Hi Thanks for your warm feedback, for your case no there is no direct way to achieve that, raw statements may be useful for this case
#94

Side note: be aware that the provided query can lead to reading phantom data.

@Sicos1977
Copy link
Author

Are you open for a pull request to support table hints?

@ahmad-moussawi
Copy link
Contributor

yes sure

@ahmad-moussawi ahmad-moussawi changed the title IF EXISTS? InsertOrUpdate Support Jun 26, 2018
@Sicos1977
Copy link
Author

Also a small question why are you using lower case for some methods?
For example the getOr() and getNot() methods? These should normally start with a uppercase G.

Do you mind if a do some code cleanup to conform to Microsoft coding rules and put that in a pull request?

@ahmad-moussawi
Copy link
Contributor

Actually I didn't find a clear documentation how to name protected variables :/, I am new to c# world :),
so go ahead if it's not aligned with C# coding guideline

@Sicos1977
Copy link
Author

It looks like you are coming from the Java world. I did send you a Pull request with support for hints and some code cleanup... more will follow. It will take me some days to cleanup everything :-). But never mind you did a fantastic job with this library.

@ahmad-moussawi
Copy link
Contributor

closing, tracking this feature on #103

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants