I am having an issue where by if I left join in conjunction with a .Distinct() I am getting an internal error.
db is LinqMetaData for Northwind.
var ord = (
from c in db.Customers
join o in db.Orders on c.CustomerID equals o.CustomerID into og
from o in og.DefaultIfEmpty()
join od in db.OrderDetails on o.OrderID equals od.OrderID into odg
from od in og.DefaultIfEmpty()
select new
{
c.CustomerID,
od.OrderDate
}
).Distinct();
This dies before any SQL generation with 'Internal error: QueryExpression of non-entity type without projection encountered without prior source with projection.' If I remove distinct it works.
If I replace the select new {} with just select u, and using distinct SQL is generated but the aliases are confused:
SELECT DISTINCT
[LPA_L4].[CustomerID],
[LPA_L4].[CompanyName],
[LPA_L4].[ContactName],
[LPA_L4].[ContactTitle],
[LPA_L4].[Address],
[LPA_L4].[City],
[LPA_L4].[Region],
[LPA_L4].[PostalCode],
[LPA_L4].[Country],
[LPA_L4].[Phone],
[LPA_L4].[Fax]
FROM ((
[Northwind].[dbo].[Customers] [LPA_L1]
LEFT JOIN [Northwind].[dbo].[Orders] [LPA_L2]
ON [LPA_L1].[CustomerID] = [LPA_L2].[CustomerID])
LEFT JOIN [Northwind].[dbo].[Orders] [LPA_L3]
ON [LPA_L1].[CustomerID] = [LPA_L3].[CustomerID])
Where it looks like [LPA_L4] should be [LPA_L1]. Now if I drop the distinct the query runs with the correct alias, but interestingly with a distinct.
SELECT DISTINCT
[LPA_L1].[CustomerID],
[LPA_L1].[CompanyName],
[LPA_L1].[ContactName],
[LPA_L1].[ContactTitle],
[LPA_L1].[Address],
[LPA_L1].[City],
[LPA_L1].[Region],
[LPA_L1].[PostalCode],
[LPA_L1].[Country],
[LPA_L1].[Phone],
[LPA_L1].[Fax]
FROM ((
[Northwind].[dbo].[Customers] [LPA_L1]
LEFT JOIN [Northwind].[dbo].[Orders] [LPA_L2]
ON [LPA_L1].[CustomerID] = [LPA_L2].[CustomerID])
LEFT JOIN [Northwind].[dbo].[Orders] [LPA_L3]
ON [LPA_L1].[CustomerID] = [LPA_L3].[CustomerID])
I know this example is a bit trivial and pointless and that I could have done some stuff that is possibly not supported by Linq to LLBLGen, but the behavior does seems a little odd.
Many thanks,
Ross
[edit]
Just looking at the above generated SQL, it looks seems to be joining to [Orders] twice rather that [orders] and [order details]. Thats [Order details] with a space... I wonder if that has anything to do with anything.