views:

42

answers:

2

In my application I am making a service call and getting back populated WCF Data Contract object. I have to display this data in a grid. Is it good practice to bind the data contract to the grid ?

Josh

+1  A: 

Assuming that all of your DTOs are friendly for data binding then shouldn't have a problem binding your WCF DTOs to a grid.

Some scenarios where you might not want to bind directly to your DTOs are:

  • Your DTOs are not easy to bind with their current definition (e.g. nested objects/properties)

  • You need to support notification of changes to the binding client (typically done using INotifyPropertyChanged)

  • You wish to insulate your UI code from changes to the WCF DTOs. This could be because you don't control the DTO definition or you expect frequent changes to the DTO definitions and you don't want to frequently change your UI code. Of course, if the DTO does change then you will have to modify code but you could isolate those changes to a small translation layer.

Tuzo
Thanks slugster and Tuzo. Your response helps a lot... :)
Josh
+1  A: 

Is it good practice to bind the data contract to the grid ?

Yes. There is nothing wrong with what you are doing.

Let me elaborate: what you have receivied back from the WCF service is a standard object (sometimes referred to as a DTO - Data Transfer Object). You have not received a DataContract - you have received an object that used a DataContract to control the serialization process between the WCF service and your client. The DataContract can control or dictate what you get, but once you have that object you are free to treat it as you wish.

slugster
Thanks for giving clear distinction in regards with WCF Data Contract and DTOs.
Josh