find a location for property in a new city

Thursday, 23 December 2010

3 things that changed ASP.NET development in 2010

As 2010 draws to a close I thought about how I was writing code last year. I realised how much development has changed in just one year. I want to look at how my work has evolved during 2010.

Entity Framework 4

I really like using Entity Framework. I wasn't quite sure about it in its first version, however, since the release of Entity Framework 4 in April I fully adopted it. It solves so many problems that I feel exist in modern web development.

I like stored procedures, I know a lot about using and optimising them but there is something seriously wrong with their concept - you have business logic in your database! When you think open mindedly about what a logical architecture should be you realise just how ridiculous that is. Entity Framework takes the last remaining strand of business logic back to the web developer.

Aside from the improvement in architecture, the other benefits I love about it is that speed you can develop with, deferred querying that improves reuse of queries, strong typing of Linq to Entities, Intellisense when writing queries, no more mapping, no more writing tedious POCOs, lack of tedious code in general.

Its hard to believe only a year ago I was writing stored procedures.


Again, I had a look into this when it was in its first version but was carried by the hype around v2. I fully adopted the use of MVC in April too and what a joy it has been to use.
A lot has changed over the last 10 years of web development such as increasing expectations of performance and web standards, popularity of unit tests and agile development, ubiquity of AJAX.

Now, I wouldn't go so far as to say there is anything wrong with ASP.NET Webforms I just feel that ASP.NET MVC has been a superb reaction to these changing trends in what web developers want to produce.

Whilst all of the above concerns can be answered by Webforms, like turning off view state to remove bloat, moving logic out of code behind to unit test, improved web standards in ASP.NET 4 etc you still feel as though you are swimming up stream some what.

I much prefer to get down and dirty with ASP.NET MVC. It's refreshing to get involved in HTML and HTTP again in a way that was abstracted out of your hands with web forms. It makes you feel like a real developer again, omnipotent! Of course the framework and templates do a lot of the tedious work for you but let's keep that quiet ay... Omnipotent! Remember that, yeah.

It's hard to think only a year ago I was using web forms.


This has obviously been around for some time but I think only during 2010 has Microsoft's commitment to open source and code contribution has really shone through. It had been displayed, proven and truly adopted by the community. Look at how much there is to gain from MVC contrib.

I would like to think this is why frameworks such as Entity Framework and ASP.NET MVC are evolving so quickly and more importantly in the right direction. Microsoft is really listening to the community now. Forums and polls about what you would like to see in the next version of Entity Framework for example.

It is not just direct listening either, I'd be extremely surprised if Microsoft weren't reading blogs, browsing stackoverflow and stalking twitter to gain insight into what the community love and what they are crying out for.

It's hard to think last year I didn't have a blog or a twitter account or contribute on stackoverflow or publish any code.

Follow britishdev on Twitter

Wednesday, 15 December 2010

WCF Data Services for using Entity Framework over REST web services

I spent some time looking into WCF Data Services 4.0 (AKA ADO.NET Data Services & Astoria) as a way to expose our Entity Data Model (EDM) over an easy to create set of RESTful / OData web services. I decided to document my findings.

WCF Data Services 4.0 is service that provides a way of exposing an EDM over RESTful (OData) web services using WCF. It means that if you have an EDM already built, the work is essentially done. The EDM can be exposed using WCF Data Services so that it can be queried directly by the client.

How to begin

I successfully set up some WCF Data Services to expose a Comment part of my model. This helped me. I did find difficulty due to our use of POCOs instead of raw Entity Framework's generated code but I found a post that helped which told me about a weird hack that overrides the CreateDataSource into the Data Service:
public class CommentsService : DataService<SocialEntities>
    protected override CommentingEntities CreateDataSource()
        var context = new CommentingEntities();
        var tracestring = context.CreateQuery<Comment>("CommentingEntities.Comments").ToTraceString();
        return context; 

Consuming the web services

A client can now access the data by requesting URLs. E.g. to get a list of messages or to get the message with ID 413 (the L is for long since I use long instead of int)

The querying gets a lot more complicated than that too. See how to use your browser to query the data model

There are many SDKs out there to begin developing against your WCF Data Services from a number of popular platforms since it is simply using the OData protocol (e.g. JavaScript, PHP, Ruby, Java, Objective-C, .NET).

Restricting use

You can restrict the number of results to return when returning a list of entities to, say 5, so the client can't overload the server/bandwidth.

You can also restrict access to select parts of your EDM to calm your security nerves too:
public static void InitializeService(DataServiceConfiguration config)
    config.SetEntitySetAccessRule("Comments", EntitySetRights.AllRead);

Evaluating when to use WCF Data Services

So it does look like a great way to use the existing EDM to instantly have a set of RESTful web services to consume. However I think I would only use this if the developers of the web service client were have knowledge of the data and are expecting to get stuck into some code when consuming our data services.

If were internally designing our own Silverlight apps then this is great. However, expecting an external user to write sometimes complex queries to get to our data using all of our business rules (e.g. IsDeleted = false && SiteID = 21) is a little much to be expected I feel.


So great when providing RESTful web services to a handful of specific clients who have knowledge of your data and business logic. Not so great for making a friendly API for the masses based on a complex EDM as you cannot expect them to understand your business rules as well as you do.

I am not claiming authority on this topic. I am just discussing my findings so far in the hope that you may find this useful. If you have anything you think I have missed please feel free to comment.

Follow britishdev on Twitter

Thursday, 2 December 2010

What motivates developers?

It concerns itself with the surprising truth of motivating people who's job requires cognitive skill (I'm taking that to include developers). It is very different from what you might you expect and explains why Linux and other open source exists.

Interesting indeed. What do you think?

Follow britishdev on Twitter