Inheritance with polymorphic collection fetch

Posts   
 
    
Robert.W
User
Posts: 79
Joined: 19-Jun-2007
# Posted on: 27-Jul-2010 13:29:04   

Hi,

using 2.6.09.917 / adapter I have a simple inheritance hierarchy based on one table with a discriminator (varchar) column

Template TemplateA : Template TemplateB : Template

let's consider following code:

var list = new EntityCollection<Template>(); adapter.FetchEntityCollection(list, null);

1) if Template is non abstract it will not fetch "polymorphically" meaning even though I have 2) all TemplateA in db they are still featched as Template it works when Template is abstract though I want scenario 1) to work so I can fetch all Template, TemplateA, TemplateB not only base classed versions

I tries introducing an intermediary

abstract TemplateBase Template : TemplateBase TemplateA : Template TemplateB : Template

without effect. Please advise.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 27-Jul-2010 21:50:23   

What happens if you do


var list = new EntityCollection(new TemplateEntityFactory());
adapter.FetchEntityCollection(list, null);

?

Matt

Robert.W
User
Posts: 79
Joined: 19-Jun-2007
# Posted on: 28-Jul-2010 08:45:17   

It seems the polymorphic collection fetch works after all, sorry for confusion. What we're actually struggling with is a single entity polymorphic fetch. In the same scenario as previously I'd like to be able to fetch:

var template = new TemplateBase(id); adapter.FetchEntity(template);

and get Template, TemplateA, TemplateB depending on what's actually in the table.

I read the explanation in the documentation for some scenarios that it would not be possible in. Is there any workaround to make it work. What is the suggested approach?

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 28-Jul-2010 08:56:19   
Robert.W
User
Posts: 79
Joined: 19-Jun-2007
# Posted on: 28-Jul-2010 10:20:37   

Thanks for pointing in the right direction. Saw that before when quickly browsing docs but FetchNewEntity didn't seem like something of interest in my scenario simple_smile Works as expected though. Thanks again.