CreateHierarchicalProjection custom projectection with relations

Posts   
 
    
Posts: 67
Joined: 10-Jun-2009
# Posted on: 24-Oct-2011 12:32:08   

Hi,

I'm trying to generate a dataset with a custom projection of a 1-n relation.

What I've got so far is this (pseudocode):


DataSet ds = new DataSet("MyDataSet");
EntityCollection<CustomerEntity> customers = new EntityCollection<CustomerEntity>();

adapter.FetchEntityCollection(customers, null, ordersPrefetch);

List<IEntityPropertyProjector> projector = new List<IEntityPropertyProjector>{
    new EntityPropertyProjector(CustomerFields.Name,CustomerFields.Name.Name);
};

customers.CreateHierarchicalProjection(projector, ds);


When I call the routine CreateHierarchicalProjection without the projector parameter, in the master table there is a relation with the child table defined.

However, I want to limit the number of columns in both tables, I don't want the PK-FK columns shown in the dataset. Therfor, I have created the projector variable. But I do want the related records in de master table.

Is there a way to get the related data as well?

Posts: 67
Joined: 10-Jun-2009
# Posted on: 24-Oct-2011 12:37:54   

sorry, little typo in the title.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 24-Oct-2011 15:28:17   

I don't want the PK-FK columns shown in the dataset. Therfor, I have created the projector variable. But I do want the related records in de master table.

Is there a way to get the related data as well?

I'm very confused by the above lines, could you please re-phrase your question.

Please use Customer-Orders analogy.

Thanks.

Posts: 67
Joined: 10-Jun-2009
# Posted on: 24-Oct-2011 15:32:58   

Or course, I'll give it a try :-)

The Customers Entity has several properties, which I don't want to export to the dataset. I do want the customers name in the dataset, but exclude it's Id property.

I want to export the Orders collection as a child table of the Customers table. In this table I want to exclude the Id property as well.

Does that make my question any clearer?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 24-Oct-2011 16:00:57   

But isn't it required to have PK-FK columns in dataTables inside a dataSet to define a relation between them. Or else how records wwill be tied up together?

Posts: 67
Joined: 10-Jun-2009
# Posted on: 24-Oct-2011 16:03:53   

I want to exclude some other fields as well.

I will first give it a try what happens if I include the PK-FK fields. I'll keep you informed.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 24-Oct-2011 16:37:47   

In general you can specify fields (as you have already did), for the List<IEntityPropertyProjector> for each entity in the Hierarchy.

Then you should include these in a List<IViewProjectionData> as follows:

List<IViewProjectionData> projectionData = new List<IViewProjectionData>();
projectionData.Add(new ViewProjectionData<CustomerEntity>(customerProjections));
projectionData.Add(new ViewProjectionData<OrderEntity>(orderProjections));

Finaly the DataSet projection should look like the following:

DataSet ds = new DataSet("MyDataSet"); customers.CreateHierarchicalProjection(projectionData, ds);

Posts: 67
Joined: 10-Jun-2009
# Posted on: 25-Oct-2011 14:42:09   

You were right: When I include the PK-FK fields, the relationships are filled and I can use them.

Thanxs!