Inheritance: Getting EntityType with FetchTypedList

Posts   
 
    
kievBug
User
Posts: 105
Joined: 09-Jan-2009
# Posted on: 11-Jan-2012 16:53:05   

Hi,

I'm using llblgen v3.1 and trying to build a query that will load data(by using FetchTypeList) from the base entity but will also include a type or table name or any other descriptor which I can use to identify which inherited entity it is. Is there anything already in llblgen for that or not? Any help is appreciated.

Example: Base entity is A and it has two entities inherited from it B and C. I want to query for the fields from A and also have a column entity type which will somehow tell me that the record is of type B or of type C.

I'm using Target-per-Entity inheritance so each entity is in separate table.

Thanks

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 11-Jan-2012 17:24:16   

So why do you want to use TypedList rather than an EntityCollection? Fetching an entityCollection would have granted you the way to check on the entityType.

kievBug
User
Posts: 105
Joined: 09-Jan-2009
# Posted on: 11-Jan-2012 17:30:04   

The main reason is joins, groupings. The data is shown in the grid so I do not need an entity it self - datatable is much easier and better solution. Base entity is related to several other entities and I want to make a join with those but not like a prefetch path; also usually I need just one or two fields from the related entity so it is just easier to get them in the query.

Anton

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 11-Jan-2012 22:55:58   

Fair enough. But then there is no built-in way for doing this.

So can you come up with the SQL Query you need to implement? Post the SQL Query (which won't be easy), then we can try to implement it with LLBLGen code.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 12-Jan-2012 12:28:34   

The way llblgen pro does it is by checking PK fields. Say you have Employee <- Manager. Fetching rows therefore should include all subtypes through joins. This then gives: [EmployeeId|Name|DateOfBirth|ManagerId|ManagerSince|.....]

If ManagerId is NULL, it's an Employee. If ManagerId isn't null, it's a Manager.

This logic is present in the InheritanceInfoProvider, retrievable from the singleton in the generated code. The method is GetEntityFactory. The problem for you is, it requires a list of indices which field is the starting point for which entity. In the example above, it's 0 for Employee and 3 for Manager.

The method will return, based on the row, the factory to create the entity class instance of the entity type the row is an instance of. As you fetch a typed list, this is likely going to be a bit fragile, as you have to produce the index dictionary and that's based on the typedlist fields, which might change and therefore your code should too. You could loop over the fields in the typed list, and build the index dictionary from that though, check the field's ActualContainingEntityName and whether it's a PK field.

Hope this helps.

Frans Bouma | Lead developer LLBLGen Pro