ObjectGraphUtils

Posts   
 
    
twaindev avatar
twaindev
User
Posts: 178
Joined: 08-Oct-2007
# Posted on: 15-Oct-2020 14:14:13   

5.7.1 RTM

ProduceTopologyOrderedList in ObjectGraphUtils returns a List of the same type as entityToExamine.

public List<TEntity> ProduceTopologyOrderedList<TEntity>(TEntity entityToExamine, out List<Type> orderedTypes)

Shouldn't this be List<IEntityCore> or something like that. Calling the method now results in an invalid cast exception when entityToExamine has instantiated related entities.

Added example:

var customer = new CustomerEntity();
customer.Company = new CompanyEntity();
var entities = new ObjectGraphUtils().ProduceTopologyOrderedList(customer, out var types);

Unable to cast object of type 'MyDomain.EntityClasses.CompanyEntity' to type 'MyDomain.EntityClasses.CustomerEntity'.

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 16-Oct-2020 00:48:23   

Please try the following:

var customer = new CustomerEntity();
customer.Company = new CompanyEntity();
var entities = new ObjectGraphUtils().ProduceTopologyOrderedList((IEntityCore)customer, out var types);
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 16-Oct-2020 08:57:15   

Indeed. The generic argument is mainly there to re-use the code between selfservicing and adapter. It would have been better if the return type was specified as a separate generic argument, agreed. But casting to IEntityCore should work.

Frans Bouma | Lead developer LLBLGen Pro
twaindev avatar
twaindev
User
Posts: 178
Joined: 08-Oct-2007
# Posted on: 16-Oct-2020 11:48:33   

I can live with that ;-) Thanks both.