Polymorphic Fetches

Posts   
 
    
morcs
User
Posts: 5
Joined: 17-Nov-2005
# Posted on: 17-Nov-2005 14:02:52   

I understand that an entity can't be fetched polymorphically through the entity.FetchEntity method, as the entity instance already has a type. Obviously in the self-servicing scenario where an entity is fetched using the constructor, the type cannot change.

I've had a look around and I can't find any solutions to fetching a new entity polymorphically (I realise that FetchNewEntity can be used but this requires a related entity in the first place). Two possible solutions would be:

  • Provide a static entity.Fetch method which would return an instance of the relevant sub-class.
  • Provide a factory method (e.g. CompanyCarEntityFactory.Get(int id).

Does anything like this already exist in the framework, or are there any intentions to add the functionality? Or am I barking up the wrong tree and asking for something which isn't actually useful?

Thanks!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 17-Nov-2005 16:16:08   

Use fetchnewentity, specify the factory of the root type of the hierarchy and the filter (doesn't need a relation/related entity, just the PK filter) and pass that as well. You'll then get a polymorphic fetch, and the entity returned will be of the type represented by the PK.

Frans Bouma | Lead developer LLBLGen Pro
morcs
User
Posts: 5
Joined: 17-Nov-2005
# Posted on: 17-Nov-2005 16:29:32   

Awesome thanks.

I'm impressed with the new inheritance mapping features. I used LLGLGen Pro at a previous company, given these new features it looks like my current company will also be purchasing!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 17-Nov-2005 16:54:56   

Cool! smile . And thanks for the compliments simple_smile It was a lot of work, to add inheritance, but it was well worth it simple_smile

Frans Bouma | Lead developer LLBLGen Pro
dals
User
Posts: 17
Joined: 10-Jul-2006
# Posted on: 25-Jul-2006 23:35:54   

Hi,

I'm still trying to understand the polymorphic fetch and when it exactly happens.

For example, I'm testing the LLBLGen with the Adventure Work 2000 (test database from MS) with MSSQL 2000.

There is an Employee table and a SalesPerson table that is a specialization for Employee.

I've already try to fetch a collection in different ways, but it never give me a instance of SalesPerson (just when I ask for it explicit).

I know it would be impossible to detect if an Employee is a SalesPerson without looking to SalesPerson table. BUT there is a column/flag in Employee table, SalesPersonFlag that tells me when it has more information on SalesPerson table. I'm wondering if would be possible to use this flag to automatic check it on SalesPerson, because I wasn’t able to use it as a Discriminator Field.

Well... I think I’ve done a fill questions in just one. Anyway this is how it organized in my mind. smile

Thank you,

David

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 26-Jul-2006 12:15:45   

Have you created a hierarchy? Such as : have you made SalesPerson a subtype of Employee? If that's the case, you will get the Employee entities which are a SalesPerson in objects of type SalesPerson with the extra SalesPerson fields filled in.

Frans Bouma | Lead developer LLBLGen Pro