Return single row for child entity

Posts   
 
    
johnd
User
Posts: 6
Joined: 09-Aug-2012
# Posted on: 09-Aug-2012 20:33:52   

Here are my tables and queries:

select r.* from Framework.StringResource r where r.Container = 'AddEditLocations'

ID Container Key

1 AddEditLocations MissingEffectiveStatus 2 AddEditLocations MissingLocationName

select rv.* from Framework.StringResourceValue rv where rv.StringResourceID in (1,2)

ID Culture StringResourceID Value

1 en 1 Effective Status is required 2 en 2 Location Name is required 23 fr 1 french Effective Status is required

select r.Container, r.[Key], rv.Culture, rv.Value from Framework.StringResource r inner join Framework.StringResourceValue rv on r.ID = rv.StringResourceID where rv.Culture = 'fr' and r.Container = 'AddEditLocations'

Container Key Culture Value

AddEditLocations MissingEffectiveStatus fr french Effective Status is required

Here is my genpro code so far...

var prefetchPath = new PrefetchPath2(EntityType.StringResourceEntity) { StringResourceEntity.PrefetchPathStringResourceValues }; var bucketContainer = new RelationPredicateBucket(); bucketContainer.PredicateExpression.Add(StringResourceFields.Container == container); bucketContainer.PredicateExpression.Add(StringResourceValueFields.Culture == culture); bucketContainer.Relations.Add(StringResourceEntity.Relations.StringResourceValueEntityUsingStringResourceId); .... EntityCollection<StringResourceEntity> resources = adapter.FetchEntityCollection(.....); .... .... StringResourceEntity entity = resources .First(r => r.Key.Equals(key));

// Problem here... -->string value = entity.StringResourceValues.First(v => v.Culture == culture).Value; <---

How do I get culture value WITH OUT filtering for it in the above line??? Since I am already filtering by container and culture, I want to set up predicate expression such that the 2 tables are joined properly and I only get a single record back AFTER MY DATABASE CALL IS EXECUTED. Is that possible?

How do I set the predicate expression that would in turn result in the following query and in this specific case return back ONLY 1 RECORD?? select r.Container, r.[Key], rv.Culture, rv.Value from Framework.StringResource r inner join Framework.StringResourceValue rv on r.ID = rv.StringResourceID where rv.Culture = 'fr' and r.Container = 'AddEditLocations'

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 10-Aug-2012 06:20:32   

In your code, you are getting back a StringResource collection filtered by some values, then you are attaching to each StringResource a collection of StringResourceValue through the PrefetchPath. If you want a single row containing the values of both entities you should use DynamicLists.

ResultsetFields fields = new ResultsetFields(4);
fields.DefineField(StringResource.Container, 0);
fields.DefineField(StringResource.Culture, 1);
fields.DefineField(StringResourceValue.Culture, 2);
fields.DefineField(StringResourceValue.Value, 3);

var bucketContainer = new RelationPredicateBucket();
bucketContainer.PredicateExpression.Add(StringResourceFields.Container == container);
bucketContainer.PredicateExpression.Add(StringResourceValueFields.Culture == culture);
bucketContainer.Relations.Add(StringResourceEntity.Relations.StringResourceValueEntityUsingStringResourceId);

DataTable dynamicList = new DataTable();
using(DataAccessAdapter adapter = new DataAccessAdapter())
{
    adapter.FetchTypedList(fields, dynamicList, bucket, 0, null, true, null);
}
David Elizondo | LLBLGen Support Team
johnd
User
Posts: 6
Joined: 09-Aug-2012
# Posted on: 10-Aug-2012 20:15:46   

Thank you .. this is working..

johnd
User
Posts: 6
Joined: 09-Aug-2012
# Posted on: 14-Aug-2012 00:19:03   

this code works for results coming back as DataTable. Is there a way for this to work such that I get back EntityCollection<StringResourceEntity> instead of DataTable?

Please advise. Thanks..

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 14-Aug-2012 19:05:49   

Your query is selecting fields from more than one entity, how come you want to return the result in a collection of one of these entities?