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

TablesInScopeHint ignores references #4321

Open
AR1ES opened this issue Oct 18, 2023 · 1 comment · May be fixed by #4363
Open

TablesInScopeHint ignores references #4321

AR1ES opened this issue Oct 18, 2023 · 1 comment · May be fixed by #4363
Assignees
Milestone

Comments

@AR1ES
Copy link

AR1ES commented Oct 18, 2023

I have complex model with many references.
When I use TablesInScopeHint(SqlServerHints.Table.NoLock) it only adds a hint for explicitly specified tables in the query but ignores references.

Classes:

public class T1 {
	public long Id { get; set; }
	public long? T2Id { get; set; }
	public T2 T2 { get; set; }
}

public class T2 {
	public long Id { get; set; }
	public string Name { get; set; }
}

Query:

var q = 
from t in db.T1
select new {
	t.Id,
	t.T2.Name
};
var res = q.ToLinqToDB().TablesInScopeHint(SqlServerHints.Table.NoLock).ToList();

Result SQL:

SELECT
	[t].[Id],
	[t_T2].[Name]
FROM
	[dbo].[T1] [t] WITH (NoLock)
		LEFT JOIN [dbo].[T2] [t_T2] ON [t].[T2Id] = [t_T2].[Id]

Expected SQL:

SELECT
	[t].[Id],
	[t_T2].[Name]
FROM
	[dbo].[T1] [t] WITH (NoLock)
		LEFT JOIN [dbo].[T2] [t_T2] WITH (NoLock) ON [t].[T2Id] = [t_T2].[Id]
@MaceWindu MaceWindu transferred this issue from linq2db/linq2db.EntityFrameworkCore Oct 23, 2023
@MaceWindu
Copy link
Contributor

@igor-tkachev FYI

igor-tkachev added a commit that referenced this issue Jan 4, 2024
@igor-tkachev igor-tkachev linked a pull request Jan 4, 2024 that will close this issue
@igor-tkachev igor-tkachev linked a pull request Jan 4, 2024 that will close this issue
@MaceWindu MaceWindu added this to the In-progress milestone Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

3 participants