Hi,
I'm facing an issue with the following query:
IQueryable<ProductsEntity> products = md.Products;
IQueryable<CustomersEntity> customers = md.Customers;
IQueryable<OrdersEntity> orders = md.Orders;
var q = from p in products
select new
{
p.ProductId,
p.ProductName,
Sum = (
from o in orders
join c in customers on o.CustomerId equals c.CustomerId
where o.EmployeeId == p.CategoryId
select o.Freight).Sum()
};
var list = q.ToList();
The generated sql query is :
Query: SELECT [LPLA_1].[ProductID] AS [ProductId], [LPLA_1].[ProductName], (SELECT SUM([LPA_L1].[Freight]) AS [LPAV_] FROM (SELECT [LPLA_2].[Freight] FROM ( [Northwind].[dbo].[Orders] [LPA_L2] INNER JOIN [Northwind].[dbo].[Customers] [LPA_L3] ON [LPA_L2].[CustomerID] = [LPA_L3].[CustomerID]) WHERE ( ( ( [LPLA_2].[EmployeeID] = [LPLA_1].[CategoryID])))) [LPA_L1]) AS [Sum] FROM [Northwind].[dbo].[Products] [LPLA_1]
With the following exception:
The multi-part identifier "LPLA_2.EmployeeID" could not be bound.
The multi-part identifier "LPLA_2.Freight" could not be bound.
I know that this query seems ridiculous and it has no meaning. I just provided it to be able to reproduce it using Northwind database.
But if I use DataSource2<TEntity> instead of IQueryable<TEntity>, every thing is fine:
DataSource2<ProductsEntity> products = md.Products;
DataSource2<CustomersEntity> customers = md.Customers;
DataSource2<OrdersEntity> orders = md.Orders;
var q = from p in products
select new
{
p.ProductId,
p.ProductName,
Sum = (
from o in orders
join c in customers on o.CustomerId equals c.CustomerId
where o.EmployeeId == p.CategoryId
select o.Freight).Sum()
};
var list = q.ToList();
For some reasons I need to reference the datasources as separate variables, so why referencing as IQueryable causes this error?
I'm using the flowing binaries:
SD.LLBLGen.Pro.ORMSupportClasses.NET20 "2.6.12.0829"
SD.LLBLGen.Pro.DQE.SqlServer.NET20 "2.6.12.0312"
SD.LLBLGen.Pro.LinqSupportClasses.NET35 "2.6.12.0829"
A sample application is attached.
Attachments
Filename |
File size |
Added on |
Approval |
LLBLNorthwind.rar
|
156,517 |
17-Sep-2012 17:43.55 |
Approved |