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

[Table] with nolock for each join tables #462

Open
BalajiDharmaraj opened this issue Apr 7, 2021 · 1 comment
Open

[Table] with nolock for each join tables #462

BalajiDharmaraj opened this issue Apr 7, 2021 · 1 comment

Comments

@BalajiDharmaraj
Copy link

How can i add table hint for each join?
var query = new Query().FromRaw("Users with (nolock)")
.Join("Authors", "Authors.Id", "Posts.AuthorId")
.Where("Id", 1)
.Where("Status", "Active");

will be:

SELECT * FROM Users with (nolock)
INNER JOIN [Authors] ON [Authors].[Id] = [Posts].[AuthorId]
WHERE [Id] = 1 AND [Status] = 'Active'

but I want it to be:
SELECT * FROM Users with (nolock)
INNER JOIN [Authors] with (nolock) ON [Authors].[Id] = [Posts].[AuthorId]
WHERE [Id] = 1 AND [Status] = 'Active'

@asherber
Copy link
Contributor

I had the same issue and tackled it by implementing my own compiler.

class NoLockCompiler : SqlServerCompiler
{
    public override string CompileTableExpression(SqlResult ctx, AbstractFrom from)
    {
        return base.CompileTableExpression(ctx, from) + " WITH (NOLOCK)";
    }
}

/*
var q = new Query("foo")
    .Join("bar as baz", "a", "b");
    
SELECT * FROM [foo] WITH (NOLOCK) INNER JOIN [bar] as [baz] WITH (NOLOCK) ON [a] = [b]
*/

It might be nice if SqlServerCompiler had a boolean property to enable this behavior out of the box.

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

Successfully merging a pull request may close this issue.

2 participants