Skip to content

Instantly share code, notes, and snippets.

@FransBouma
Last active July 7, 2016 11:26
Show Gist options
  • Save FransBouma/0f2d71c85e7784422a84007158579bb9 to your computer and use it in GitHub Desktop.
Save FransBouma/0f2d71c85e7784422a84007158579bb9 to your computer and use it in GitHub Desktop.
Table/view hint specification in LLBLGen Pro v5.1 Linq queries
[Test]
public void TwoHintOnJoinedElementTest()
{
using(var adapter = new SqlReadDataAccessAdapter())
{
var metaData = new LinqMetaData(adapter);
var q = from c in metaData.Customer
.WithHint("NOLOCK")
.WithHint("FORCESEEK")
join o in metaData.Order on c.CustomerId equals o.CustomerId
where o.EmployeeId > 4
select c;
var results = q.ToList();
Assert.AreEqual(83, results.Count);
var expectedQuery = "SELECT DISTINCT [LPA_L1].[Address], [LPA_L1].[City], [LPA_L1].[CompanyName], [LPA_L1].[ContactName], [LPA_L1].[ContactTitle], [LPA_L1].[Country], [LPA_L1].[CustomerID] AS [CustomerId], [LPA_L1].[Fax], [LPA_L1].[Phone], [LPA_L1].[PostalCode], [LPA_L1].[Region] FROM ( [Northwind].[dbo].[Customers] [LPA_L1] WITH(NOLOCK, FORCESEEK) INNER JOIN [Northwind].[dbo].[Orders] [LPA_L2] ON [LPA_L1].[CustomerID] = [LPA_L2].[CustomerID]) WHERE ( ( ( [LPA_L2].[EmployeeID] > @p1)))";
Assert.AreEqual(expectedQuery, adapter.LastGeneratedCommand.CommandText);
}
}
[Test]
public void TwoHintOnJoinedElementWithHintOnQueryableTest()
{
using(var adapter = new SqlReadDataAccessAdapter())
{
var metaData = new LinqMetaData(adapter);
var q = from c in metaData.Customer
.WithHint("NOLOCK")
.WithHint("FORCESEEK")
join o in metaData.Order.Where(x=>x.OrderId>10).WithHint("NOLOCK") on c.CustomerId equals o.CustomerId
where o.EmployeeId > 4
select c;
var results = q.ToList();
Assert.AreEqual(83, results.Count);
var expectedQuery = "SELECT DISTINCT [LPA_L1].[Address], [LPA_L1].[City], [LPA_L1].[CompanyName], [LPA_L1].[ContactName], [LPA_L1].[ContactTitle], [LPA_L1].[Country], [LPA_L1].[CustomerID] AS [CustomerId], [LPA_L1].[Fax], [LPA_L1].[Phone], [LPA_L1].[PostalCode], [LPA_L1].[Region] FROM ( [Northwind].[dbo].[Customers] [LPA_L1] WITH(NOLOCK, FORCESEEK) INNER JOIN [Northwind].[dbo].[Orders] [LPA_L2] WITH(NOLOCK) ON [LPA_L1].[CustomerID] = [LPA_L2].[CustomerID]) WHERE ( ( ( ( [LPA_L2].[OrderID] > @p1)) AND ( [LPA_L2].[EmployeeID] > @p2)))";
Assert.AreEqual(expectedQuery, adapter.LastGeneratedCommand.CommandText);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment