tags:

views:

28

answers:

3

I have WPF DataGrid which get his data from Web Service. End user has ability to customize visible columns in DataGrid.

1st approach:

I get this data in xml and after convert xml to the dataTable and give it like ItemsSource for DataGrid.

2nd approach:

Also I can get this data like class array from service (for example Customer[])

Problem:

I use 1st approach with extra steps for the purpose not get redundant data from service. In 2nd approach if user see only two columns in DataGrid (one column for one property in class) he get all class with all his filled properties (redundant data). in 1st approach he get only data xml which will be visible in datagrid in UI.

But I use MVMM approach in my project and I dont want to use xml and dataTable approach. I think I have to use 2nd approach, but in this case I get redundant data

A: 

I would take the second approach even though this may transport a little bit more data. If you really want control over what fields are fetched, this will probably make your application more complex then necessary.

Have you verified you have performance problems with the second approach?

Pieter
For example I have class which has 80 properties but user want to see only several of them .
Polaris
Is it an option to have to server only set the properties on the customer that you need? In that case, you are receiving the customers in a customer object so it's easy to use in WPF, but you're still only transporting the data that you require.
Pieter
A: 

It is a just another trade-off we have always faced when developing softwares.

In your specific case,

First approach has performance advantage by transfering much less (not sure if really much) data on network and flexibilty by not using strongly typed data approach.

Second approach is looking better for manageability and easy development in the long term.

To choose the right approach you should consider and weighting non-functional requirements such as performance, extensibility, manageability etc.

orka
+1  A: 

In 2nd approach if user see only two columns in DataGrid (one column for one property in class) he get all class with all his filled properties (redundant data)

If the above is the only thing that is stopping you with your second approach, then C# v4.0 has Named and Optional Arguments feature. Which works as

Console.WriteLine(Calculate(weight: 123, height: 64));

even if the actual Calculate() has 99 arguments, with any order.

Please note, I assume, that by redundant you mean, unwanted data.

KMan