Dataset projection and join with another table

Posts   
 
    
Ajornet
User
Posts: 3
Joined: 15-Apr-2008
# Posted on: 04-Apr-2009 19:52:39   

Hello,

I have three tables in master-details schema : zones => secteurs => uga.

I can get a dataset with three datatables with the joined code.

But in the table "zones", I have an ID for a manager which complete name's is in the table "responsables".

How can I get the complete name in my projection in order to get it in the first datatable.

Any help will be welcome

Best regards Daniel

Here's the code

 var zones = new EntityCollection<ZonesEntity>();
            var path = new PrefetchPath2(EntityType.ZonesEntity);
            path.Add(ZonesEntity.PrefetchPathSecteurs).SubPath.Add(SecteursEntity.PrefetchPathUga);
            using (var adapter = new DataAccessAdapter()) {
                adapter.FetchEntityCollection(zones, null, path);
            }

            // setup projections per type.
            List<IEntityPropertyProjector> zonesProjections = EntityFields2.ConvertToProjectors(
                    EntityFieldsFactory.CreateEntityFieldsObject(EntityType.ZonesEntity));

            List<IEntityPropertyProjector> secteursProjections = EntityFields2.ConvertToProjectors(
                    EntityFieldsFactory.CreateEntityFieldsObject(EntityType.SecteursEntity));

            List<IEntityPropertyProjector> ugaProjections = EntityFields2.ConvertToProjectors(
                    EntityFieldsFactory.CreateEntityFieldsObject(EntityType.UgaEntity));

            List<IViewProjectionData> projectionData = new List<IViewProjectionData>();
            projectionData.Add(new ViewProjectionData<ZonesEntity>(zonesProjections, null, false));
            projectionData.Add(new ViewProjectionData<SecteursEntity>(secteursProjections, null, false));
            projectionData.Add(new ViewProjectionData<UgaEntity>(ugaProjections));

            var result = new DataSet("projectionResult");
            zones.CreateHierarchicalProjection(projectionData, result);
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 05-Apr-2009 22:15:49   

Hi Ajornet, This is what you should do:

  1. Add a custom property on a ZonesEntity's partial class that return the responsable's name:
string ManagerName
{
     get
     {
          string toReturn = string.Empty;
          if (Responable != null)
         {
               toReturn = Reponsable.CompleteName;
         }

         return toReturn;
     }
}
  1. Add the Responsables prefetchPath to the path:
path.Add(ZonesEntity.PrefetchPathResponsables);
  1. Add that property to your zonesProjections:
zonesProjections.Add(new EntityPropertyProjector(new EntityProperty("ManagerName"), "ManagerName"));
David Elizondo | LLBLGen Support Team
Ajornet
User
Posts: 3
Joined: 15-Apr-2008
# Posted on: 06-Apr-2009 08:57:39   

Hi,

Before my post, I've tried to use the two last points, in vain.

I have done all the three points but I got a crash.

I've found a solution :

1) I have added in the designer, a field to my ZonesEntity, based on the related table.

2) and 3) as you wrote.

And now, all run fine.

Is it a good solution or not ?

Thanks Daniel

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 06-Apr-2009 11:23:47   

Yes, you got it right.

Ajornet
User
Posts: 3
Joined: 15-Apr-2008
# Posted on: 06-Apr-2009 11:29:37   

Hi,

thanks to both.

Daniel