Bug projecting from an 8 table join

Posts   
 
    
TomDog
User
Posts: 623
Joined: 25-Oct-2005
# Posted on: 27-Aug-2008 04:02:09   

As part of my efforts to Linqafy http://www.codeplex.com/RapidDevBookCode I attempted a Linq version of a TypedList

      var customerlist = from customer in AWHelper.MetaData.Customer
                         from customerAddress in customer.CustomerAddress
                         select new
                                  {
                                    customerAddress.Address.AddressLine1,
                                    customerAddress.Address.AddressLine2,
                                    customerAddress.Address.City,
                                    AddressType = customerAddress.AddressType.Name,
                                    customer.Individual.Contact.Title,
                                    customer.Individual.Contact.FirstName,
                                    customer.Individual.Contact.MiddleName,
                                    customer.Individual.Contact.LastName,
                                    customer.Individual.Contact.Suffix,
                                    customer.Individual.Contact.EmailAddress,
                                    customer.Individual.Contact.EmailPromotion,
                                    CountryRegionName = customerAddress.Address.StateProvince.CountryRegion.Name,
                                    StateProvinceName = customerAddress.Address.StateProvince.Name,
                                    customer.CustomerId
                                  };
      if (MaxNumberOfItemsToReturn > 0)
        customerlist = customerlist.Take(MaxNumberOfItemsToReturn);
      bindingSource1.DataSource = customerlist;

When I ran it I got a SQL error; Here is the trace:

An exception was caught during the execution of a retrieval query: The multi-part identifier "LPLA_4.AddressLine1" could not be bound.
The multi-part identifier "LPLA_4.AddressLine2" could not be bound.
The multi-part identifier "LPLA_4.City" could not be bound.
The multi-part identifier "LPLA_5.Name" could not be bound.
The multi-part identifier "LPLA_7.Title" could not be bound.
The multi-part identifier "LPLA_7.FirstName" could not be bound.
The multi-part identifier "LPLA_7.MiddleName" could not be bound.
The multi-part identifier "LPLA_7.LastName" could not be bound.
The multi-part identifier "LPLA_7.Suffix" could not be bound.
The multi-part identifier "LPLA_7.EmailAddress" could not be bound.
The multi-part identifier "LPLA_7.EmailPromotion" could not be bound.
The multi-part identifier "LPLA_9.Name" could not be bound.
The multi-part identifier "LPLA_8.Name" could not be bound.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception.

: Initial expression to process:
value(SD.LLBLGen.Pro.LinqSupportClasses.DataSource`1[AW.Data.EntityClasses.CustomerEntity]).SelectMany(customer => customer.CustomerAddress, (customer, customerAddress) => new <>f__AnonymousType1`14(AddressLine1 = customerAddress.Address.AddressLine1, AddressLine2 = customerAddress.Address.AddressLine2, City = customerAddress.Address.City, AddressType = customerAddress.AddressType.Name, Title = customer.Individual.Contact.Title, FirstName = customer.Individual.Contact.FirstName, MiddleName = customer.Individual.Contact.MiddleName, LastName = customer.Individual.Contact.LastName, Suffix = customer.Individual.Contact.Suffix, EmailAddress = customer.Individual.Contact.EmailAddress, EmailPromotion = customer.Individual.Contact.EmailPromotion, CountryRegionName = customerAddress.Address.StateProvince.CountryRegion.Name, StateProvinceName = customerAddress.Address.StateProvince.Name, CustomerId = customer.CustomerId)).Take(5)
Method Enter: CreatePagingSelectDQ
Method Enter: CreateSelectDQ
Method Enter: CreateSelectDQ
Generated Sql query: 
    Query: SELECT DISTINCT TOP 5 [LPLA_4].[AddressLine1], [LPLA_4].[AddressLine2], [LPLA_4].[City], [LPLA_5].[Name] AS [AddressType], [LPLA_7].[Title], [LPLA_7].[FirstName], [LPLA_7].[MiddleName], [LPLA_7].[LastName], [LPLA_7].[Suffix], [LPLA_7].[EmailAddress], [LPLA_7].[EmailPromotion], [LPLA_9].[Name] AS [CountryRegionName], [LPLA_8].[Name] AS [StateProvinceName], [LPA_L1].[CustomerID] AS [CustomerId] FROM ( [AdventureWorks].[Sales].[Customer] [LPA_L1]  INNER JOIN [AdventureWorks].[Sales].[CustomerAddress] [LPA_L2]  ON  ( [LPA_L1].[CustomerID] = [LPA_L2].[CustomerID]))

Method Exit: CreateSelectDQ
Method Exit: CreatePagingSelectDQ: no paging.

To reproduce this using the project code run the app then open the Customers form then press the ‘Linq Barf’ button. Strangely I can get this to work by adding a meaningless where clause e.g.

var customerlist = from customer in AWHelper.MetaData.Customer
                         from customerAddress in customer.CustomerAddress
                         where customerAddress.Address.AddressLine1 == customerAddress.Address.AddressLine1
                         select new…

DB is Adventure Works(2005)

Jeremy Thomas
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 27-Aug-2008 07:13:49   

Reproduced (RTL= 2.6.8.819). Only happen if Take/_TakePage _is used.

Thanks Jeremy, we will look into it.

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39865
Joined: 17-Aug-2003
# Posted on: 27-Aug-2008 10:48:37   

Looks like when hops over more than 1 entity are specified in the query it fails. Support for this is build in, so it should work as expected. I'll look into it.

(edit) indeed, David, Take() ruins it. confused Without Take it works fine... something small I think...

(btw, Individual is a subtype of Customer btw, not sure if Joseph had that originally in his work, it could be nice to have Individual as a subtype of Customer)

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39865
Joined: 17-Aug-2003
# Posted on: 27-Aug-2008 11:28:18   

Fixed it. See attached assembly.

Frans Bouma | Lead developer LLBLGen Pro
TomDog
User
Posts: 623
Joined: 25-Oct-2005
# Posted on: 28-Aug-2008 03:08:44   

Otis wrote:

(btw, Individual is a subtype of Customer btw, not sure if Joseph had that originally in his work, it could be nice to have Individual as a subtype of Customer)

No there's no mention of inheritance in his book alas.

Thanks for the quick response Frans - that sorted itsimple_smile However I came across something else:cry http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=14181

Jeremy Thomas