Target Per Entity relationship

Posts   
 
    
mattsmith321 avatar
Posts: 146
Joined: 04-Oct-2004
# Posted on: 29-Mar-2006 21:12:31   

We had the following schema before Target Per Entity (obviously simplified):

Family

FamilyID Name

Events

EventID FamilyID Title StartDate EndDate

Tasks

TaskID FamilyID Title Priority

There was a 1:m relationship from Family to Events and also to Tasks.

We used to have the following line of code: EntityCollection events = family.Events;

Now, with Target Per Entity, we have the following schema (simplified):

Family (no changes)

FamilyID Name

BaseItem

ID FamilyID EntityType Title

Event

ID StartDate EndDate

Task

ID Priority

We need something similar to: EntityCollection events = family.Events; but we only have access to: EntityCollection events = family.BaseItems;

I tried creating the relationship in the designed (Jan 30th release) but did not have any luck.

I'm assuming that the only way to get what we want is to filter by our EntityType discrimator field?

Any help is appreciated!

Thanks, Matt

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 30-Mar-2006 03:25:21   

That's true you won't be able to make a direct relationship, but you could use a prefetch path to fill baseItems with only Events or Tasks. The other option would be to define a new collection in the generated code for event and task that when filled would apply the required filter on the relationship to fill the collection correctly.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 30-Mar-2006 10:14:11   

To elaborate a bit on bclubb's comment: the relation is set between Family and BaseItem. Fetching BaseItem is always going to bring any subtype into that collection. If you want only events, you can perform a prefetch path for BaseItem and with that prefetch path specify a filter on the Event type. Please see Using the generated code -> Adapter -> Filtering and sorting -> Advanced filter usage -> Filtering on entity type. There you'll learn how to retrieve a filter on a given entity type (here EventEntity) you then have to specify that as the filter with the prefetch path node for Event (path.Add(FamilyEntity.PrefetchPathBaseItems, 0, new PredicateExpression(EventEntity.GetEntityTypeFilter()));

Frans Bouma | Lead developer LLBLGen Pro
mattsmith321 avatar
Posts: 146
Joined: 04-Oct-2004
# Posted on: 30-Mar-2006 16:11:58   

Otis wrote:

To elaborate a bit on bclubb's comment: the relation is set between Family and BaseItem. Fetching BaseItem is always going to bring any subtype into that collection. If you want only events, you can perform a prefetch path for BaseItem and with that prefetch path specify a filter on the Event type. Please see Using the generated code -> Adapter -> Filtering and sorting -> Advanced filter usage -> Filtering on entity type. There you'll learn how to retrieve a filter on a given entity type (here EventEntity) you then have to specify that as the filter with the prefetch path node for Event (path.Add(FamilyEntity.PrefetchPathBaseItems, 0, new PredicateExpression(EventEntity.GetEntityTypeFilter()));

Sweet! Thanks for the extra detail and the pointer to the correct location in the doco (I really do read it! It's just that all my effort has been focused in the table inheritance sections the past few days). This should get us where we need to be. Yesterday was a fun day making our first steps into switching to TPE. While we are probably a ways from actually being able to run, at least we got things compiling cleanly. Yay!