FetchEntityCollection and TargetPerEnity

Posts   
 
    
Toddles
User
Posts: 2
Joined: 02-Feb-2005
# Posted on: 22-Oct-2006 04:19:32   

Hello,

Listing -Residental -Condominium -VacantLand

I'm trying to determine how to implement search for a TargetPerEntity inheritance hierarchy similar to the layout above.

For instance, Listing has fields for things like price. The subtypes have fields that are specific to that type such as number of bedrooms.

I can easily create a query that returns all listings within a certain price range. In this case I'll get an EntityCollection of Listings that are actually subtypes such as Residential or VacantLand.

Is it possible to do the same type of thing but include additional predicates for the subtype fields such as number of bedrooms? or Do I specifically have do a FetchEntityCollection for each subtype?

Here is the code I'm currently using to do the actual Fetch. The bucket parameter is dynamically created based on my search criteria.

private static EntityCollection RunSearchQuery(IRelationPredicateBucket bucket, int pageNumber, int pageSize, out int totalResults)
        {
            EntityCollection ec = new EntityCollection(new ListingEntityFactory());         
            using (DataAccessAdapter adapter = new DataAccessAdapter(true))
            {
                totalResults = (int)adapter.GetDbCount(new ListingEntityFactory().CreateFields(), bucket, null, false);
                adapter.FetchEntityCollection(ec, bucket, pageNumber, null, pageNumber, PAGE_SIZE);
            }
            return ec;
        }

The bucket predicates are built using code like this.

private static IPredicateExpression BuildActiveStatusPredicate()
        {
            IPredicateExpression pStatusPredicateExp = new PredicateExpression();
            pStatusPredicateExp.Add(ListingFields.ST == "A"); //active
            pStatusPredicateExp.AddWithOr(ListingFields.ST == "C"); //contingent
            pStatusPredicateExp.AddWithOr(ListingFields.ST == "D"); //active - sti
            return pStatusPredicateExp;
        }

If I try to add a predicate for the subtype fields, then an exception is thrown that the field could not be bound. Is what I want possible?

Thanks! -Todd

Chester
Support Team
Posts: 223
Joined: 15-Jul-2005
# Posted on: 22-Oct-2006 21:03:16   

The problem is that you're getting a collection with only the supertype entity in it, so you can't do a comparison to fields that are in the subtypes without adding those relations into the query.