Bill Blogs in C#

Bill Wagner discusses C#, LINQ, and other items of interest

March 2004 - Posts

Question and Answer on creating and using DataBinding in your own types.

Q: When you bind to business objects, then you not only want to bind
to the properties of the objects, often you want to display properties
of related objects.
 
Example: You have a DataGrid displaying a list of Order objects, the
class Order has a property OrderCustomer that returns a object of class Customer.
When you now display a list of Orders, then whenever you add the
OrderCustomer column to the grid you get a string containing the
name "Cstomer". I guess this happens, because the databinding mechanism
calls object.ToString() on each property. I can think of many instances
where it would be very useful to display the Customer Name in the row
of an order, so this would be a property of a property. 

A:
You are correct.  You get the "Customer" output because of the default ToString behavior. If you override the Object.ToString() method in your Customer object to return the Name property, that behavior would change.

On a case to case basis, this can be achieved if you would define a
property Customer_Name in the Order class. But then there are so many
possibilities, and it does not make sense to code all of these possibilities
when you do create the class. In a certain sense, you then do not follow
the object oriented programming paradigm.
 
I don't think it makes sense to create a list of all properties and sub_properties
that a class has; I believe that there must be a smarter way to do that.
 There are three ways to do this.  Which makes the most sense depends on your application.
 
1: Use the datagrid navigation paradigm.  In this version, you "drilldown" from the Order table into the selected customer(s) in the customer table. This works well when the users will view the navigation up and down the hierarchy using the DataGrid navigation strategy.
 
2: Expose individual sub-properties as you described above. This is the best choice when you have a small number of properties to add.
 
3: Create a new combined data-binding class that contains both the customer and the order objects, and therefore exposes both. This is somewhat of a heavy-weight version of 2.  However, you can use some data-tier logic to create a combined set using a join.



The referenced article.
The original article on DataBinding
Posted by wwagner | with no comments
Filed under: ,
Should web services maintain state?

Q: I've read your articles in Visual Studio Magazine.

I was wondering if you knew how to keep “state” in a web service relative to properties.

Meaning if I do something like this :

Dim objCustomersWS as new webservice.class
objCustomersWS.Name
objCustomersWS.Address

which are properties set in the web service, is it possible to get these values on the client side? I have tried and can not achieve this.

A: Keeping state in the web service class, on the server, is a bad idea. It leads to a very chatty API between the server and the client.

Looking at your very trivial example above, you’ve already made two round trips to the server. Expand that design to an application of any reasonable size, and your application will have dreadful performance. It’s far better to view the web service as an object server: you request an object from the server, modify it on the client, and then send the results back to the server:

Dim objCustomersWS as new webservice.class
Dim customerObj as
webservice.Document
customerObj = objCustomersWS.RetrieveCustomer
objCustomersObj.Name = newName
objCustomersObj.Address = newAddr
objCustomersWS.SubmitCustomerChange( customerObj )

You retrieve a customer (or set of customers) from the server, make all the modifications locally, then send it back to the server.

I hope that helps.



Visual Studio Magazine
Much writing here.
Posted by wwagner | with no comments
Filed under:
How do I get started with the compact framework

Q:

The other day at the GANG meeting you demo’d how to create a compact .net application.  I recall you said it came with Visual Studio 2003.  I just tried to “reproduce” what you did and when I create a new project I only see Mobile Web Application in addition to the usual ASP.Net, Console, Windows, Web Services types.

 I’m running Visual Studio.Net 2003 Standard Edition.  Do I need to download an SDK or get a different version?

A:

What you want to build smart device application, using the Compact Framework. The .NET CF home page has links to download the SDK:

 

What you probably want is to upgrade to VS.NET Professional, which contains wizard and designer support for the .NET CF.  That seems to be lacking from the standard edition.

 



GANG website
The home of our .NET User Group
.NET Compact Framework
Where to learn about the .NET CF
Posted by wwagner | with no comments
Filed under: