Layered Design and DataSets for Dummies

Scott Hanselman does a nice 30 second intro into layered design. If any of this is new to you, run quickly to read this.

Scott does a quick bash at Datasets (although doesn't say why) and in my new role as DataSet boy I have to disagree with him and evangelize how simple datasets can make a lot of the code written by the typical programmer: CRUD stuff for example. He even mentions “Adapter“ in describing a data access layer - come on, use the DataAdapter - don't be afraid. In general, if anybody tells you to never do something, you need to question that a bit and dig into the reasons why a technology exists. Of course things may just end up being rude and the answer is indeed never - but always try and get the why.

We've been running a developer contest at the end of some of our training courses (the big 3 week immersion ones). The competition has developers build a solution build on a services oriented architecture which includes smart client, web services, enterprise services/com+ and of course data access. It's only a 1 day event, but the teams are built up of 5-6 people each. Inevitably, if one team decides to use datasets/dataadapters and the other team doesn't, the team that choose the dataset wins. This competition isn't judged or skewed for datasets by any means. But inevitably this is the thing that gives the other team more time to work on the interesting pieces of the application (like business logic: features and functions).

I over heard Harry Pierson tell a customer last week that they shouldn't use datasets in a web service because they aren't compatible with non .NET platforms. This isn't true. A dataset is just XML when you return it out of a dataset. And you probably more control over the format that is generated via the XSD than most people realize. If you want a child table nested, no problem. You want attributes instead of elements, no problem. You want some columns elements and others attributes, no problem. You want/don't want embedded schema, no problem. You don't want the diffgram, no problem. Somebody in the J2EE world has actually gone to the extent of creating a similar type of base object in Java that can deserialize the dataset in most of it's glory. (Link to come - can't find it right now).

In February I posted a “Benefits of Datasets vs. Custom Entities“ which has generated some excellent feedback. It's still in my plans to write the opposite article - when Customer Entities are better than Datasets but I'm still looking for the best template or example entity. Everyone somebody has sent me to date is somewhat lacking. To be fair, I end up always comparing them to a dataset. The things typically missing out of a custom entity are the ability to deal with Null values and the ability to track original values for the purposes of optimistic concurrency. The answer to the question of “When to use a Custom Entity over a Dataset?“ is of course when you don't need all the stuff provided for you by a dataset. So is that typically when you don't care about Null Values or Optimistic Concurrency? Perhaps. But I know there is more to it than that.

I will say there is some crummy binary serialization in the dataset (it's really XML). This is really a problem if you are doing some custom serialization or need to do some .NET remoting. But you can change the way they are serialized (and indeed it's changed in Whidbey). There are some good examples here, here, here, here, here and here.

I'm working on an article making the cases for the custom entity, but in the meantime, datasets represent a good design pattern for entities that is easy and quick to implement by the average developer - and scalable too.

Classes or XML Documents

One of the Four Basic Tenets of Service Orientation states that “services share schema and contract, not class”. This means the interface for a service should be based on an XML schema.  This runs counter to the interface for a managed class, where the type

Lowering the Barrier to Entry

If you've been wondering how you can afford a copy of Visual Studio .NET 2003 for playing with at home, you're request has been granted.  Simply watch and review five of the VB at the Movies installments found here and you'll get a certificate for a free Standard Edition.  Not a bad deal at all.

MSN API and Lazy Programming?

In my never ending quest to please Barry I've decided to post another blog, 2 in as many days.

A couple weeks ago I was reading Eli Robillard's blogs on Lazy Programming, simply happy that someone had blogged a topic I could relate to. As a side note, Eli's wife Marcie is an amazing person who would do anything to help a friend and colleague get what they need.... more on this later hopefully.

If you haven't read Eli's posts on Lazy Programming I strongly recommend it, and don't write it off just cause it has the word Lazy in it, you will regret it.
All this talk of laziness got me thinking of my own laziness. I decided that my own laziness is my greatest source of inspiration. The greatest of all the little programs and web apps I've created have been 'lazy' induced, apps to work for me, so I didn't have to.

The most current of the lazy projects is my MSN Assitant. I got tired of waiting for certain people to sign-on to MSN, but I hate being told about EVERY person that signs-in. So I created a little program that would pop-up some toast when the person I was looking for came online. Easy enough.
Only a few weeks later the next problem revealed itself. From the couch I could see that someone had written me, but I couldn't read who, or what was being said.
Now if you are an enthusiastic person you might be yelling at me to get off the couch, but I'm not like you. So the solution was clear, I needed to work in Microsoft Speech and the MSN API so that when a message is delivered it can be read to me. Depending on the message I can then decide for myself if I should get off the couch, I'm actually liberating myself from MSN.

MSN API - The MSN API for MSN 4 was an amazing bit of work, simple and easy to use. You could send and receive messages, look through your contacts, simply great.
The API for MSN 6, is simply put, horrible. I'm sure there were some excellent security reasons behind the changes to the API (better have been). Microsoft decided to remove the built in capability to send and receive messages. Unfortunetly MSN 6 has better functionality so you won't find many people using MSN 4. MSN 4 API will not work if the user has MSN 6 running.

So I can't easily receive messages, as a lazy person my first instinct is to quit, my cost/benefit analysis is thrown all out order, but the potential pay off is WAY to great.

So I stumbled upon MSN Fanatic which is a great resource site for the MSN API, they had some good suggestions. Basically involving using the WinAPI's to read from the textbox's the comprise a standard msn conversation window. This seemed plossable, but a pain, so I went the easy way, monitor the conversation history, strip out the new line, if it was spoken by someone otehr than me, speak it.

Microsoft Speach SDK - Another brilliant little peice of work, if you are looking for something nice and simple that will read some text, this is a dream. A couple of lines of code and your computer is reading to you in a selection of voices ( that pretty much all sound the same if you ask me )

Incremental Search

Barry found this and showed me some time ago. I had forgot about it and stumbled across it today. I keep forgetting it's there. I'm hoping by Blogging it I will remember.

When you are editing code in Visual Studio hit CTRL-I. You will see this little icon appear,  this is Incremental Search.

Once in this mode you can just start typing and it will find text that matches what you are typing as you type.

If you have typed the whole word but search has not found the one you want, hit F3 to jump to the next occurrence.


TechEd (Day 3): Hands On Lab Manuals downloads available to the public

No need to have a TechEd commnet password. You can download ALL the pdf's for the plethora of topics. Some good stuff to see how the newly announced stuff (Team System, etc.) works.

Update These links are broken, give this a try:

How does dynamic help work?

Did you ever wonder how dynamic help works? The Visual Studio IDE continuously emits keywords and attributes depending on what you are doing in the IDE. Lets start by turning on debugging in Visual Studio. I don't mean the kind of debugging you do to your code. It's easier if I just show you. Follow these steps. Don't worry it's harmless.

  1. Close Visual Studio .NET if it is not already closed.
  2. Open the Windows Registry Editor (RegEdit).
  3. Go to the following key:
    HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\7.0\Dynamic Help
  4. Add a new string value of "Display Debug Output in Retail" with a value of "YES."
  5. Start Visual Studio .NET.
  6. Open the Dynamic Help

Now open a solution and start working, watch the dynamic help window you will see the keywords displayed in the Dynamic help window as you manipulate your code in Visual Studio.

For example if I were to click on a windows form in VB.NET I would see the following in my Dynamic help window.

--- Keywords - priority: 500 ---
(F1 Kwd) Keyword=Designer_System.Windows.Forms.Design.FormDocumentDesigner
(Kwd) Keyword=System.Windows.Forms.Form
--- Keywords - priority: 100 ---
(Kwd) KEYWORD=VS.Ambient
--- Attributes ---

What you are seeing are the keywords and attributes emitted by Visual Studio. This is how Dynamic help works. You can add your own custom help that displays different help links based on keywords emitted from the IDE.

Ok, so now that I know how to get the keywords, how do I add my own custom help? This is a Blog not an article so I'll give you the abridged version, you can look up the rest yourself.

Create a file called CustomHelp.xml and place it in C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE\HTML\XMLLinks\1033

Here is what a sample CustomHelp.xml file could look like. Some nodes to take note of:

  • LinkGroup defines a heading in the help to group the links
  • Keywords/Kitem define which keywords trigger this help to display
  • Links/Litem the URL for the help file, the link group it belongs under, and the text to display

The above CustomHelp.xml file will generate dynamic help that looks like this. Well the last group called ObjectSharp Coding Standards

The keyword I used in the sample above (Ambient) is a special keyword. It is always present. Therefore if you want a help file to always be accessible use the keyword ambient in your CustomHelp.xml.

As I'm sure you can tell I have only scratched the surface on this subject. There is plenty more information in the MSDN library.

Tech Ed Bloggers

There are a bunch of ObjectSharp people and Friends of ObjectSharp at Tech Ed this week. Their Blogs are making good reading. I feel like I'm there. If you wish you had gone to Tech Ed or wonder what you are missing. Check out the Blogs below.

ObjectSharp People

Friends of ObjectSharp

Everyone else

Monad, it isn't just danom backwards anymore.

I'll be the first to admit that I haven't been paying a whole lot of attention to Longhorn. I went to the token meeting, I listen to Barry and Dave, but that's about as far as my indoctrination goes. However, maybe today that changes. I started to read a couple articles on the Monad Shell (MSH).

The Monad Shell is Microsoft's kick at the powerful shell engines you find in the *nix systems. As a recent graduate from the academic world which is ruled by the *nix systems, I've always held that a decent shell engine is what Windows lacked the most (I've also added a decent file search engine now).

MSH introduces the new concept of a Commandlet (Cmdlet), these cmdlet's are the new .exe, .bat, or .com with a twist. The cmdlets are in fact .NET libraries, more closely related to a DLL than an EXE.

With the help of reflection and metadata inside the class, MSH will validate and map command line parameters to the properties of your class/cmdlet. Metadata is also the mechanism that MSH uses to identify a normal class library from a cmdlet.

So far this all sounds somewhat interesting, and maybe useful, but the best is yet to come.
Piping. Microsoft has done something great here, they have taken the already great idea of piping and improved it 100%. Gone are the days of piping text, here are the days of piping objects. Here is one of the examples from the WinHEC presentation. get-process | where “handlecount –gt 400” | sort handlecount | out-chart processname,handlecount I think its pretty self-evident what is happening here except perhaps the last piping command. out-chart will apparently output the results into an excel chart using the associated values of processname and handlecount. All of these commands now return an output stream that contains and object, not just a flat string representation of what SHOULD have be an object. The cmdlets have access to more than just the single output stream as well, by default they have the output stream, and an error stream. Also available are verbose, debug, and progress streams.

Seamless Navigation. I haven't tried this myself, but it would be nice if it turns out to be true. Microsoft claims that the new shell will enable seamless navigation between the: File system, Registry, AD, and WMI. Lets hope that's the case.

Now, I just need to find a place to install longhorn so I can try all this great stuff out.

The slides from WinHEC can be found here.

Anyone played with this yet? Let me know what you think/thought.

The Immediate Window

I notice a lot of developers do not use the Immediate window. If you are one of those users,  do yourself a favour and check it out. It's terribly useful. For those of you who are not familiar with it here are some highlights to get you started.

The window I'm talking about in VS 2003 is the Command Window. This window can be used to either issue commands or to debug and evaluate expressions in Visual Studio .net. To open this window, press CTRL+ALT+A, or click on the menu View->OtherWindows->Command Window

For the record I believe I heard these two windows will be seperated in Whidbey.

Below is a quick description of the two modes.


Title Bar Displays Description
Command Mode Command Window Allows the developer to perform any command available in Visual Studio via a command line interface.
Immediate Mode Command Window - Immediate Used when debugging an application for evaluating expressions, print variable values, or execute statements. It can also be used to change the value of a variable during debug or even to execute a function or statement.

How to switch between the two modes?

  • When you are in command mode you can enter the command >immed to switch to immediate mode.
  • When you are in Immediate mode you can switch to command mode by typing >cmd
  • If you wanted to execute one command in immediate mode prefix it with a > ie: >alias

Immediate Window:

This is the mode I use most. It's like a command line quickwatch, but it has intellisense. To evaluate an expression you must prefix it with a ?

  • ?this.Order.OrderTable(0).itemarray
  • ?this.Order.OrderTable(0).CustomerId
  • ?this.Order.OrderTable.count

In previous versions of the Immediate window the UP and DOWN ARROW keys move the cursor to previous commands. In VS .Net they allow you to scroll through previously issued commands. If you scroll to a command highlight it and hit enter it will be copied as the next command to be executed.
Once in a project, the Command window can be opened in Immediate mode by pressing CTRL+ALT+I, or click on the menu Debug->Windows->Immediate.

One more quick tip. You can copy your command from the immediate window into the watch window. So in other words get it right with the help of intellisence then paste it into the watch window so you can see it permanently.

The Command Window:

Just to give fair time to both modes. The Command Window makes full use of intellisense to help you find and execute a command within VS.

You can also create your own alias for any command for example: You can type the following to save all the files in your solution.


However, if you used this command a lot you could create a shorter alias of this command like fs.
To create an alias enter the following into the command window.


From now on you can just type fs to perform a file.Saveall

To see a complete list of aliased commands just type alias in the Command Window and it will list all the aliased commands.