C# Code
using (DataAccessAdapter.NoLockAdapter adapter = new DataAccessAdapter.NoLockAdapter())
{
LinqMetaData metaData = new LinqMetaData(adapter);
var q = (from om in metaData.OrderMaster
select om);
PrefetchPath2 p = new PrefetchPath2((int)EntityType.OrderMasterEntity);
p.Add(ContractMasterEntity.PrefetchPathCustMaster);
q = q.WithPath(p);
if (orderId != null && orderId.Length > 0) // orderId == collection of order IDs
{
q = q.Where(all => orderId.Contains(all.orderId));
}
if (orderStatus != null && orderStatus.Length > 0) // orderStatus == collection of statuses to look for
{
q = q.Where(all => orderStatus.Contains(all.Status));
}
// Paging code
if (startAt == null)
{
q = q.Skip(0);
}
else
{
q = q.Skip((int)startAt);
}
if (count == null)
{
q = q.Take(100);
}
else
{
q = q.Take((int)count);
}
if (q != null)
{
return ((ILLBLGenProQuery)q).Execute<EntityCollection<OrderMasterEntity>>();
}
}
First query:
exec sp_executesql N'SELECT DISTINCT TOP 50 [LPA_L1].[OrderNumber], [LPA_L1].[DataSource], [LPA_L1].[CustomerId], [LPA_L1].[StoreId], [LPA_L1].[TypeOfSale], [LPA_L1].[Status], ... FROM [Master].[dbo].[OrderMaster] [LPLA_1] (nolock)) [LPA_L1] WHERE ( ( ( ( ( ( ( ( [LPA_L1].[StoreId] IN (@StoreId1))) AND ( [LPA_L1].[Status] IN (@Status2, @Status3)))))))) ORDER BY [LPA_L1].[CreationDate] DESC',N'@StoreId1 varchar(18),@Status2 varchar(3),@Status3 varchar(3)',@StoreId1='1234',@Status2='OPN',@Status3='CLO'
Second query:
exec sp_executesql N'SELECT [Master].[dbo].[Cust_Master].[Customer_ID] AS [CustomerId], [Master].[dbo].[Cust_Master].[Data_Source] AS [DataSource], [Master].[dbo].[Cust_Master].[First_Name] AS [FirstName] ... FROM [Master].[dbo].[Cust_Master] (nolock) WHERE ( [Master].[dbo].[Cust_Master].[Customer_ID] IN (SELECT [LPA_L1].[CustomerId] FROM (SELECT [LPLA_1].[OrderNumber] AS [OrderNumber], [LPLA_1].[Data_Source] AS [DataSource], [LPLA_1].[Customer_ID] AS [CustomerId], [LPLA_1].[Dealer_ID] AS [StoreId], [LPLA_1].[Type_Of_Sale] AS [TypeOfSale], [LPLA_1].[Status] .... FROM [Master].[dbo].[OrderMaster] [LPLA_1] (nolock)) [LPA_L1] WHERE ( ( ( ( ( ( ( ( ( [LPA_L1].[StoreId] IN (@StoreId1))) AND ( [LPA_L1].[Status] IN (@Status2, @Status3)))))))))) AND [Master].[dbo].[Cust_Master].[Data_Source] IN (SELECT [LPA_L2].[DataSource] FROM (SELECT [LPLA_1].[OrderNumber] AS [OrderNumber], [LPLA_1].[Data_Source] AS [DataSource], [LPLA_1].[Customer_ID] AS [CustomerId], [LPLA_1].[Dealer_ID] AS [StoreId], [LPLA_1].[Type_Of_Sale] AS [TypeOfSale], [LPLA_1].[Status] ... FROM [Master].[dbo].[OrderMaster] [LPLA_1] (nolock)) [LPA_L2] WHERE ( ( ( ( ( ( ( ( ( [LPA_L2].[StoreId] IN (@StoreId4))) AND ( [LPA_L2].[Status] IN (@Status5, @Status6)))))))))))',N'@StoreId1 varchar(18),@Status2 varchar(3),@Status3 varchar(3),@StoreId4 varchar(18),@Status5 varchar(3),@Status6 varchar(3)',@StoreId1='1234',@Status2='OPN',@Status3='CLO',@StoreId4='1234',@Status5='OPN',@Status6='CLO'
Post the LLBLGen Pro version + buildnr - 2.6 Final (April 15, 2009)
Runtime library version - 2.6.9.511
Post the template group + .NET version you're using - Adapter, .NET 3.5
Post the database type and version you're using -- SQL Server 2005, running with 2000 DQE compatibility mode
The code above is somewhat obfuscated due to NDA.
If it's not clear or helpful, please let me know.
Edit:
OrderMaster has a composite primary key on OrderNumber and Data_Source
Cust_Master has a composite primary key on Customer_ID and Data_Source
OrderMaster has a foreign key to Cust_Master, Customer_ID -> Customer_ID and Data_Source -> Data_Source