Typed Lists from inherited Entities.

Posts   
 
    
dkrants
User
Posts: 8
Joined: 23-Mar-2011
# Posted on: 25-Mar-2011 22:25:06   

I'm using LLBLGn 3.1 to generate EF v.4 model and I came across an issue when using Typed List from an inherited entity.

I'll use **AdventureWorks **database as an example:

  1. I've made Sales.SalesPerson a HumerResources.Employee.
  2. I've created the typed list called **SalesPersonShort **with fields: EmployeeId,Title and SalesYTD. LLBLGen validates the model fine.
  3. Now I oped the generated code in VS and try to build the project it giev an error:

AW.AdventureWorksEFDataContext' does not contain a definition for 'SalesPeople' and no extension method 'SalesPeople' accepting a first argument of type 'AW.AdventureWorksEFDataContext' could be found.

I've looked at the code of the Get... method and it's got the following

public IQueryable<SalesPersonShortTypedListRow> GetSalesPersonShortTypedList() { var current0 = this.SalesPeople; return current0.Select(v=>new SalesPersonShortTypedListRow() { Title = v.Title, EmployeeId = v.EmployeeId, SalesYtd = v.SalesYtd } ); }

So why LLBLGen generates a code referencing **SalesPeople **when there's no such property?? confused How do I make LLBLGen generate the correct code?

The correct code in this case would be var current0 = this.Employees.OfType<SalesPerson>();

Of cource I can correct it manually but it's real PIA to do it every time after I generate the code.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 26-Mar-2011 06:43:44   

Reproduced. We will look into this asap.

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 26-Mar-2011 11:17:13   

Bug in template. We'll fix it on monday. (it's on line 148 of contextClassInclude.lpt, in Frameworks\Entity Framework\Templates\Shared\C#)

It has to check whether the type to return is an inheritance type, it doesn't. We've to check whether other areas in that linq query generation code needs adjustment as well.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 28-Mar-2011 11:37:45   

Fixed in next build.

I've attached a new set of templates for EF to this post. Unpack the archive as administrator into: llblgen pro installation folder\Frameworks\Entity Framework\Templates\

overwriting existing files. We changed the general utils template and the contextinclude template for vb.net and C#.

Frans Bouma | Lead developer LLBLGen Pro
dkrants
User
Posts: 8
Joined: 23-Mar-2011
# Posted on: 28-Mar-2011 20:23:48   

This fixed it. Thanks for your quick response!