Related fields in EntityCollections

Posts   
 
    
e106199
User
Posts: 175
Joined: 09-Sep-2006
# Posted on: 11-Jul-2009 00:31:18   

Hi, if i have entity1 and entity2 related to each other, i can reach the fields of entity2 from entity1 like Order.Customer.Fullname.

is it possible to add related fields into an entity collection with the same simplicity? i can create a typed list or typed view that shows the order details and the customer fullname.

what would be the best way to accomplish this without creating typed list/view?

thanks in advance

-shane

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 11-Jul-2009 05:29:22   

Mmm. It's not like that, as a collection is a container of entity objects, so normally you access related data between entities not between containers. How would you like to access the related data from collection?

David Elizondo | LLBLGen Support Team
e106199
User
Posts: 175
Joined: 09-Sep-2006
# Posted on: 11-Jul-2009 06:36:16   

daelmo wrote:

Mmm. It's not like that, as a collection is a container of entity objects, so normally you access related data between entities not between containers. How would you like to access the related data from collection?

ok my bad. i dont think my explanation was clear. it will be a readonly list, nothing like accessing related data between entities.

here is what i have:

                    IncludeFieldsList includedFields = new IncludeFieldsList();
        includedFields.Add(StaffFields.FullName);

        PrefetchPath path = new PrefetchPath(EntityType.GradeLevelEntity);
        path.Add(GradeLevelEntity.PrefetchPathStaff, includedFields);

        IPredicateExpression filter = new PredicateExpression();
        filter.Add(GradeLevelFields.AcademicYearId == academicYearId);

        GradeLevelCollection toReturn = new GradeLevelCollection();
        toReturn.GetMulti(filter, 0, null, null, path, includedFields, 0, 0);

gradelevel collection is bound to a datagrid and has 2 columns; gradeleveldescription and fullname. somehow fullname wont show even though there is a staff assigned for every gradelevel. i was hoping the gradelevel collection would return all filtered gradelevels with the staffs fullname using the prefetch path defined.

tha name of the field is FullName and this is what i use in my columns datafield value. DataField="FullName". somehow it returns nothing. any ideas what might be wrong?

thanks -shane

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 12-Jul-2009 06:46:32   

Hi Shane,

The FullName column is a field of Staff, right? If that is the case, you should create a custom property that return such property of the related entity (Staff). You also could add that field as a field on related field of the GradLevenEntity at LLBLGen Designer (more info...).

David Elizondo | LLBLGen Support Team
e106199
User
Posts: 175
Joined: 09-Sep-2006
# Posted on: 12-Jul-2009 21:41:51   

daelmo wrote:

Hi Shane,

The FullName column is a field of Staff, right? If that is the case, you should create a custom property that return such property of the related entity (Staff). You also could add that field as a field on related field of the GradLevenEntity at LLBLGen Designer (more info...).

yes fullname belongs to staff table. how can i create a custome property with keeping the grids data source as the gradelevel entity collection?

thank you -shane

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 13-Jul-2009 02:31:43   

At, GradeLevelEntity CUSTOM_CODE, or at a GradeLevenEntity partial class, write something like:

public string FullName
{
     get
     {
          string toReturn = string.Empty;
          if (Staff != null)
          {
               toReturn = Staff.FullName;
          }
          return toReturn;
     }
}

This is done automatically if you add the field as related field. This way, it will look like if GradeLevelEntity have a field named FullName. (read more about adding fields on related fields).

David Elizondo | LLBLGen Support Team