Wednesday, 21 October 2009

.Net 4 – Enable standard controls for dynamic data

Just seen a new blog post by Scott Hunter today about some of the data enhancements that are coming for .Net 4.0.

The thing that got me excited was at the very bottom of the post where he mentions changes to the way dynamic data can be used.

What you should be able to do is attach dynamic data functionality to a existing control simply by specifying the extension method EnableDynamicData so to add the functionality to a ListView you would just enter:

ListView1.EnableDynamicData(typeofProduct))

This would then provide all the normal dynamic data functionality for that control. Sweet!

Sunday, 18 October 2009

Silverlight 3 – dialog

Had one of those thick moments the other day whilst trying to debug a silverlight 3 app.

Used the new SaveFileDialog and the debugger was throwing an error when the dialog attempted to execute the .Open method.

It took me a moment to realise that the problem was that the browser needed to execute the action and that the action being executed by the code represented a security risk.

Once I ran the code to a point after the .Open I could debug to my hearts content.

Unity configuration intellisense

I’m late to the whole IOC party and since in work we use the Enterprise Library as our standard for majority of functionality we may want (like logging, error handling, etc) so Unity is the first stop I’ll make for an IOC.

Now the first thing I expected was to have intellisense to help me with the configuration so you can imagine my surprise when after I referenced the assembly the Enterprise Library configuration tool didn’t offer me ability to configure unity and when I dropped into the web.config to add the config manually there was no intellisense.

So I opened google and had a look around and found Unity Community Contributions which contains a set of extensions to unity one of which is an xsd that provides intellisense (its easiest to get it here as you can down load it by itself outside of the main project).  There is one draw back - you have to configure each project that you want to use it with, you can’t set it up so that its used by default each time.

Once you’ve downloaded it you need to Place the xsd in <drive>:\Program Files\Microsoft Visual Studio 9.0\Xml\Schemas.

To be able to use it you need to configure the properties of the config file that you will be putting the unity config in.  To do this open the config file and then go to the properties pane where you will find a property called schemas.

At the end of the schemas property you find the standard … button to open a dialog.

You should find the unity xsd listed and all you have to do is to select use and click ok and then you’ll have intellisense.

Friday, 2 October 2009

Web forms a dead end?

Read a blog post by Dino Esposito The dead-end of Web Forms which is where Dino says:

When introduced, Web Forms was a cutting edge solution and it just engineered current best practices. But it was ten years ago. We could argue whether it was the right choice to engineer ASP practices ten years ago. There's not much more you can expert or achieve with Web Forms than you do today. OK, tomorrow, with version 4. This is the dead-end of Web Forms.

Does it mean that no more development will be done on web forms by Microsoft, I doubt it, will there be a lot of new development, that depends.

Web forms is a mature product this means that any changes to it will be incremental amending/enhancing existing functionality to improve how it works rather than jumping forward with innovative new functionality.

If you look at the changes in .Net 4.0 we see some of the new functionality being introduced having already been developed for MVC, for example routing, and I think going forward you will this trend increase with new functionality appearing in MVC first and then being added to web forms afterwards. 

If Microsoft themselves believe that web forms has hit a dead end then why not open it up to the community as open source the same way as MVC, if this happened at worst no changes would be made by the community but at best you may see new innovation and the product revitalised.

 
In the end that there are most likely 10’s of thousands of web sites built using web forms and they are not going to be replaced overnight with MVC. Web forms may be ‘a dead end’ as Dino puts it but a lot of people will be employed to maintain, extend and yes build sites with web forms for a good number of years yet.

Sunday, 27 September 2009

TDD, Unit Test or nothing?

I’ve been thinking about unit testing recently prompted by a talk at .Net Developer Network, a presentation recorded at Agile 2009 and a blog post by Joel Spolsky.

Now I try hard to remain open minded about different methodologies but that doesn’t mean I won’t ask questions about them and often find that the way that the people involved who are ‘championing’ the methodology answer those questions effect my attitude towards it.

In the recent talk at .Net Developer Network given by Stephen Oakman and Ronnie Barker of the Agile workshop  they focused on using TDD, in this case Test Driven Design, to create an application but being very disciplined (strict?) and following TDD to the letter:

  • write test
  • test fails
  • write just enough code to pass test or refactor existing code.
  • test passes
  • check in to source control.
  • Repeat

Now I have no objection to that know I haven’t been doing pure TDD which has prompted me to look into it further – a good thing.

What did occur to me though is the amount of time it takes to create the code although Steve & Ronnie say you get faster as you go along I felt myself wanting to take a bigger step forward than they were doing i.e. write a bit more actual code rather than lots of small tests. 

My issue, if you like, is that the process seemed to take a very long time and although it would have been thoroughly tested it will still need to have the tester go through the code, remember “unit tests prove the correctness of the code, testing proves correctness of the functionality” but I also know what my manager would say with the increased time to finish any piece of work.

The next day Joel Spolsky blogged about ‘The Duct Tape Programmer’ which seemed to be the complete opposite of what Steve and Ronnie talked about and I can understand the desire to simply ‘code it’.  I have also recently watched a presentation by J B Rainsberger called ‘Integration tests are a scam’ which did highlight the fallacy of some of the testing we as developers do.

I think that as developers we need to use our own judgement as to what we test and whether the investment in writing tests will pay off for example should you bother writing tests for an application that consists of a single call to the database to record minimum information and has a half life of about a month?

I fully believe in unit testing this doesn’t mean pure TDD but does mean writing tests, if you can utilise the VS ‘Create unit test’ functionality’ or if you can use a tool like PEX to generate edge cases and the other tests that would take a long time to create then use it and save yourself time and be happy that your code is tested.

Friday, 25 September 2009

Asp.Net Dynamic Data – Attributes

I’ve been doing some more dynamic data and trying to work with the meta data for a table to change the display.

Previously I’ve mentioned ordering columns and although not explicitly mentioned it the hiding of columns you don’t won’t by applying the [ScaffoldColumn(true)] attribute where you set true so DD generates a column and false if you don’t want it displayed.

The attributes that I can find in relation to display of the data are:

Attribute Name Description
Scaffold Column Indicates if column should be displayed or not
DisplayName Name to be displayed in the header of the column for the property
DefaultValue Default value to use when inserting new data
Description Text to show in a tooltip when mouse hovers over the field
DataType Used to specifies the name of a type to associate with a data field to provide additional functional around that field e.g EmailAddress
UIHint Used to specify the FieldTemplate to use when rendering the column.
DisplayColumn Specifies the column to display for filters or foreign keys.  Default is to use first string column that is found

Over the next few posts I’ll being going into these attributes to show the source code and the results.

Original post

Monday, 17 August 2009

Hotfix breaks live code

I have spent near enough all of today trying to fix a system that was broken by the automatic application of a Microsoft hotfix, specifically KB958484 Application Compatibility Update.

The first that I knew of any issue was when this morning discovered that one of our live sites had stopped working around 3am Sunday morning.  A little digging turned up that a windows update had been applied at this time, KB958484.

This gem of a hotfix changed the behaviour of the XmlSerializer so that where as before the hotfix if a class had a read only property the serializer just ignored the property, now the serializer threw an exception saying Unable to generate a temporary class (result=1). error CS0200: Property or indexer 'Person.Id' cannot be assign to -- it is read only

A bit of googling showed that I was not the only person experiencing problems in relation to this but a lot of the solutions weren’t very enlightening many mentioning that you needed to  use *Specified, and googling that didn’t turn up anything immediately apparent.

What it comes down to is using the attributes specifically related to Xml serialization like [XmlElement], now since the properties that were being complained about were public read only i.e. couldn’t be used for deserialization simply adding the attribute [XmlIgnore] resolved the issue.

Wednesday, 12 August 2009

Asp.Net Dynamic Data & Column ordering

As I've mentioned I'm just getting started with dynamic data and uncovering various things that I need to overcome or work around.

The first actual dynamic data issue, rather than linq-to-sql, was limiting the fields that were displayed so I created my class with a MetadataType attribute and I only got the columns that I want to display.

The next challenge was changing the name of a column, again this was easy all I needed in the meta data class was another attribute DisplayName and I could set the name of the column.

The final challenge I faced was needing to reorder the columns since I needed the fields to appear in a different order. So I googled for an attribute I could use to do this and found...nothing.

Out of the box dynamic data, in its current form, does not support re-ordering of columns. To me this seemed such a fundamental thing I was surprised that I couldn't do it.

So I googled some more to see if there were any solutions, custom code, extensions etc that I could find to provide the functionality.

The futures site popped up immediately and that has this functionality plus so much more, only issue is that I wasn't comfortable deploying the futures code for a production system.

So I carried on searching and thats when I found Dynamic Data Columns Ordering, an entry on the MSDN code gallery that contained code that you needed to add to your project and changes to make to existing files and then you just added a ColumnOrder attribute to the meta data and the column appears in the right order.

Sorted!

Sunday, 9 August 2009

Asp.Net Dynamic Data - first glance

So this last week when I've actually managed to get time to do development I've been working with Asp.Net dynamic data using Linq-to-Sql for data access.

My first impressions were quite good, create a model, provide the data context set the scaffolding to true and there you have an application. It all seems very easy, but then as with most things you try and do something that it doesn't really want to do and things become difficult.

As I've mentioned before some of the difficulties are related to Linq-to-Sql not doing what its supposed to but some of it is related to dynamic data.

Much like what I see as failings with Linq-to-Sql dynamic data seems to offer the ability to create UI with no or very little custom coding suggesting that if you want to change the standard behaviour you simply need to provide an attribute and you can change the way that the 'application' is generated.

Unfortunately this isn't the case, there are some attributes you can use such as [DisplayName] but at present these are few and far between.

As I get deeper into dynamic data I'm going to post what I've found, what you can do and what you can't.

Wednesday, 5 August 2009

Linq-to-Sql multiple views of the same data

In my previous post I mentioned the problems I have been having with Linq-to-Sql so I thought I'd elaborate on my difficulties.

Before now I hadn't used Linq-to-Sql but had seen demo's, web casts, etc that made it seem all so easy so I started work with high hopes. I set about adding a linq-to-sql file to the solution opened up the server explorer and added a table, all went well, but it was about to all go down hill rapidly.

Up to now I've done the majority of data access using stored procedure and was used to getting data from a table in any shape I wanted. My first problem with Linq-to-Sql was that I wished to have different views of the data in a single table and thought I should easily be able to define these views but this functionality simply is not available.

Now in linq's defence I don't remember it saying is should allow this type of functionality but as I said I had high hopes, I did find I could drag as many instances of single table into the model (got warning messages when I built but no other apparent problems) and I could then remove fields add properties etc but it felt wrong.

So for now this is what I've done, don't know if its the best or only way but will do for now.


Tuesday, 4 August 2009

Asp.Net Dynamic Data & Linq-to-Sql

Over the last few days I have been, when possible, trying to get to grips with Asp.Net Dynamic Data and Linq-to-Sql.

My first impression - its not what I expected.

It seems to be more difficult than it should be to be able to define the O/R mapping not to mention the little issue of the autogenerated datacontext disappearing if you extend the partial class and happen to name the class file the same as the .dbml file. Only turned on to the problem by a post on stackoverflow.

As I get more to grips with dynamic data I'll post more, for now I'm tending to pull my hair out trying to get it to do what should be simple

Monday, 3 August 2009

The first post

This is the first post on my blog.

My intention is to use this as a bit of a memory dump for me and along the way I may find some interesting things to talk about and would love for people to comment on what I've blogged, as I find you learn more through discussions rather than lectures.

The title? well thats what I do and all the cool names had already gone ;)

I'm currently working with Asp.Net technologies (webforms, MVC, dynamic data) and my next few posts will most likely cover them but I have been toying with going back to the beginning and doing a deep dive on web as a platform to refresh my memory.

Most of my posts will be about technology but I may digress now and then.

I can't promise I'll blog all the time but hopefully what I do blog will be interesting.