September 2007 - Posts

DevConnections Hot New Stuff
24 September 07 06:58 PM | despos | with no comments

Be among the first to register for a new full-day pre-con workshop at DevConnections--Las Vegas, Nov 5.

APR306: Building AJAX Applications with ASP.NET 3.5 (9:00AM - 4:00PM)
Dino Esposito
Each AJAX application, regardless of the underlying platform, has a common 2-tier architecture where a front-end and a (multi-tiered) back-end talk by exchanging JSON packets over HTTP. In ASP.NET 3.5, the first version of ASP.NET to incorporate AJAX natively, you have two options for building applications—-partial rendering and script services. Partial rendering doesn’t give you any architectural shift but is quick to apply and learn. If you opt for services, then you need JavaScript and DOM to build up a nice interface for the user. This means, however, a lot of client coding in an interpreted environment and subject to bugs and memory leaks of some browsers. In this workshop, we’ll first carefully review the technical details of partial rendering and script services and then put everything into perspective by going through a series of realistic scenarios and architectural considerations. 

A lot of code to see and dissect. We'll be using VS 2008, but everything being discussed really applies also to ASP.NET 2.0 with AJAX Extensions applied.

Add'l Fee $399

Filed under:
LinqDataSource vs ObjectDataSource vs SqlDataSource
24 September 07 06:43 PM | despos | 11 comment(s)

With ASP.NET 3.5, a new data source control joins the company: the LinqDataSource control. How does it position itself in the grid of data source controls?
The difference between SqlDataSource and ObjectDataSource is fairly clear. The first leads you to add SQL code directly in the markup of ASP.NET pages, which is not certainly a practice to recommend even though the resulting page will still work great. ObjectDataSource is right the opposite. It pushes the use of objects and makes the binding between  data-bound controls and data sources happen through made-to-measure objects. In most cases, the objects bound to ObjectDataSource won’t be just the top layer objects of your business tier. But ObjectDataSource allows you to preserve—and, to a good extent, it mandates you to have—a well designed business tier.
What about LinqDataSource, instead? To me, it falls somewhere in between the other two. 

I should have read somewhere that one of the advantages of LinqDataSource over ObjectDataSource is that it doesn't require you code manually the source of the classes in the object model. Uhmmmm. Tell me, what's your priority being a developer/architect?

If you're simply trying to save yourself a few hours of development, aiming at a longer weekend home with the family, then by all means pick up the LinqDataSource control. If, instead, your priority is the overall design of the application, then just forget about LinqDataSource; just as much as you should have forgotten about SqlDataSource.

To enable Linq-to-SQL (and subsequently LinqDataSource), you necessitate to create a data model—better if through the O/R designer embedded in Visual Studio 2008. This data model is rooted in a data context class and contains initially only data container classes, with data properties but no behavior. The idea behind LinqDataSource is that you use the auto-generated object model to manage data and provide any required behavior through direct injections of Linq-to-SQL commands. As you can see, the pattern behind LinqDataSource and SqlDataSource is nearly the same. The only difference is the language you use: Linq-to-SQL in one case, raw SQL in the other. Another key difference that must be noted between SqlDataSource and LinqDataSource is that SqlDataSource can accommodate any relational data source, whereas LinqDataSource is limited to SQL Server. 

The purposes of LinqDataSource and ObjectDataSource are clearly different. ObjectDataSource enables you to take advantage of RAD data binding on top of your existing middle tier. LinqDataSource and related tools give you instead a quick way to build an extremely thin and to some extent, anemic, object model that, in addition, can hardly be deployed on a physically different tier.

The bottom line that I see here is that you should only consider ObjectDataSource for enterprise class applications and wherever the complexity of the domain model is significant. LinqDataSource is a much smarter replacement for SqlDataSource with the current technological limitation of being limited to SQL Server.

This said, I wouldn't bother using either SqlDataSource or LinqDataSource for applications with a very simple domain model, a trivial business logic, or just in the context of temporary pages that are to be quickly arranged and just work. 

Using Linq-to-SQL in the Data Access Layer is all another story, instead. As long as your data store is SQL Server, Linq-to-SQL may be an excellent replacement for T-SQL and its underlying data model returns objects rather than tables as in VS 2005 table adapters. This is much more powerful and easy to maintain. But the interface towards the middle tier must still be rendered using contracted data transfer objects leaving the middle tier in charge of talking to the presentation and ASP.NET pages. If you intend to use data source controls for this, ObjectDataSource is the only option you have.

 

Travel Agenda for Next Weeks
19 September 07 09:28 AM | despos | 1 comment(s)

My next stops around the world. It would be nice to see there somewhere, somehow :-)

Filed under:
Partial Rendering Misses AJAX Architectural Points
19 September 07 09:19 AM | despos | 10 comment(s)

Partial rendering is one of the two approaches that ASP.NET AJAX propounds. It works by applying the Interceptor pattern and hooking up the submit event of the form. The event handler then kicks in and operates the intercepted request via XMLHttpRequest instead of going through the browser. From the perspective of the ASP.NET runtime, business is as usual. So the request goes through the usual lifecycle and fires Init and Load events, and handles the postback and updates the viewstate. Undoubtedly, it keeps flickering out of pages and contributes to an overall greatly improved user experience. Undoubtedly, it is relatively cheap both in terms of required skills and impact on existing code. Properly optimized, it can lead to significant bandwidth improvement.

Should we call this AJAX?

AJAX is about a change of paradigm for the Web where we place requests-for-data instead of submitting forms-for-pages. Nothing of this happens with partial rendering. So should still we call this AJAX? And, frankly, does it really matter? Architecturally speaking, partial rendering is not AJAX for the simple reason that the underlying application model remains the same. There's no new architectural point in partial rendering. But partial rendering remains an excellent way to enhance existing applications.

Can we simply conclude with a sounding "Who cares if it's not pure AJAX?"

Partial rendering still misses some of the key features of AJAX--one in particular. So a model that doesn't support concurrent async operations, should be labeled as pure AJAX? I don't know whether we should or not. Partial rendering has many strengths, including that of simplifying the development of an AJAX-based user interface. However, it doesn't allow concurrent async calls. If you place two consecutive clicks for postback and the second fires before the former has terminated, then the ongoing call is aborted to make room for the second. Why is it so? To avoid breaking the viewstate and the overall consistency of the state. On the other hand, the pre-AJAX web works by making one call at a time. Why should partial rendering then be different?

What does it mean to you?

Use partial rendering whenever you feel, but be aware of its inherent limitations. In practice it mostly means that you have to disable all controls that can fire a postback during a refresh. If you need multiple calls at the same time, use then script services and trigger them entirely on the client via JavaScript. And as a free additional tip, avoid doing polling via partial rendering. In other words, avoid the use UpdatePanel with Timer controls, unless strictly necessary or if it's the minor evil. The issues are viewstate and bandwidth. Potentially too much data moving over the wire too frequently. A script service commanded by a client-side timer (the old faithful window.setTimeout) would do the job more efficiently.
 

Filed under:
Silverlight and the Year of the Back
18 September 07 09:27 AM | despos | with no comments

Yeah, it's been a while since my last post. Summer is hard here in Italy and makes you terribly lazy. Wives and kids go and leave you alone with a lot of time to spend in pleasant activities such as working overnight and playing tennis during the hottest hours of the day. Until you get injured. Once it is tendinitis; once it is hamstring; once it is the back or the shoulder. For me this has been the year of the back :) 

Getting ready for DevConnections, Las Vegas, Nov 5, I shared some thoughts about Silverlight with DotNetSlackers.com. You can read the full (and brief) story here. But I want to anticipate some of the thoughts.

  • Silverlight rocks. But I'm talking about the Silverlight that's not here yet. Ah Ah
  • Silverlight 1.0 is just media. Which is way too great. But with the asp:Media control is even better. Unfortunately, the control is in ASP.NET Futures and not usable in real apps
  • Silverlight vReal needs layout, input, data binding to start with. Without that is lame.
  • A thing like Silverlight may be the formula to make RIA and AJAX apps easier to write.

PS: What? Writing AJAX apps is hard? Was it the hot Italian summer to hit you like this? With partial rendering it takes a moment to ajax-ify virtually any Web... STOP. You said it: partial rendering. On a side note, partial rendering is great but is not AJAX. But I still like (and use) it. But I can't help but repeating that AJAX architectures are hard to achieve without a serious and powerful platform for presentation layer. The pair JS+DOM is too brittle and at high risk of poor performance; pregenerated markup is a trick; Silverlight (or something similar from a non-MS world) may be the answer.

My two final cents of this hot summer. Until next.

Filed under:
More Posts