Ruby on Rails Watch out here comes Blinq

18 June, 2006 (17:49) | General | By: Thomas

Ok I’m being a little dramatic. Nonetheless Blinq is a lot of fun. In case you haven’t kept up, in the past few weeks/months MS has been posting CTP versions of some of its next generation data access technology. And yes, I guarantee a lot off people will be confused by all the LINQ related initiatives out there. And many will proclaim the wonders of this latest technology. Truth be told, some of it is pretty cool – even to a jaded old grump like yours truly. But contrary to all the proclamations that will be made by wide eyed neophytes, and taken as gospel truth since blog posts don’t come with resumes attached,  a good many features have been available through other venues. But that is the subject of another post altogether.

Here is what Polita Paulus, the creator of Blinq writes about its purpose: “Blinq is a tool for generating ASP.NET websites for displaying, creating, and manipulating data based on database schema. Just point Blinq at a SQL database and it will create a website with pages that display sorted and paged data, allow you to update or delete records, create new records, and follow relationships between tables in your database. You don’t need to write SQL queries to use Blinq; LINQ will generate optimized queries for you that request just the data you want to show. Blinq uses the May LINQ Community Tech Preview to access data. The code Blinq creates is simple and easy to customize to fit your needs. Everything in the website Blinq creates is meant as a starting point for a website that meets your needs perfectly, so have fun customizing the pages, experimenting with the code, and making it yours!”

Would you like to see how it works?

For starters Polita is has done a marvelous job in creating this utility. It works as advertised. And it does very much what Ruby on Rails accomplishes with scaffolding.  But it does it in a very different way. Unlike RoR which is very MVC and proper OO oriented, Blinq is more of a 2 tier ( or 1.5 tier) approach. So it will be wonderfully productive for all those small little pesky utility jobs but cannot be thought of as anything more than a quick UI prototype for bigger apps. But thats really a good thing. I am so sick of wiring presentation to middle tier code that it was very refreshing to simply execute 1 command line and have it spit out an entire working app. Therein also lies one of the caveats of this tool. It works best against a properly designed database. Don’t  throw it against the old war-horse at the office and expect it to work magically. Secondly let me emphasize one more time – this thing rocks for quick UI’s that can then be built out every which way both in the aspx / atlas realm of things and the middle tier and database end.

My test was run against a SQL database that is used to manage site content. Ideally the db needs a UI with it and much more functionality to turn it into a CMS. So here is what I got after 5 seconds of Blinq’ing – wonder if Paula called it Blinq because if you do you miss the entire generation process.  

Here is the main entry point to the app

MainPage

Going further into it, here is what the functionality around one single table looks like. All the buttons work. The columns sort and everything is wired and ready to go

 

TblLocalizations

 

 

 Here is what it looks like if I want to enter a new record. Since the table consists purely of key values,  its not all that interesting to look at.

 

TblLocalizationNew

 

 

But as you look over these images do you notice a few very interesting aspects here? There are breadcrumb menus across the top, the menu on the left you will see in one minute is very interesting, and the grids of course are sorting and paging. Not bad. Let’s go look under the hood.

Blinq executes on the command line. So one single statement points the utility to the right directory and database, everything else is automated. Here is what the directory looked like after running it. Blinq generated a Masterpage, various page sets (Master / Details) as well as a skin, found in App_Themes. At first the lack of code behind files is a little unsettling. But thats the result of declarative datasources in the aspx pages and some centralized classes in App_Code.

 

FileStructure

 

 

The App_Browsers directory contains instructions that drive which menu and assembly to use to produce the menu for different browsers. The App_Code directory is much more interesting.
In my case, the directory contains two files – dbSiteContent.cs a file that contains the mapping of tables and columns to datatypes in a LINQ understandable manner. Think Hibernate and NHibernate without all of the XML files. Personally I appreciate mapping in code and not in XML.So here is what the mapping code looked like for this particular example.If you’ve worked with different object mappers chances are some of this looks familiar.

 

DbSiteContent

   

The second file contained in that directory is called StaticMethods. As far as I know, it is these methods that are mapped to by the aspx pages and respective ObjectDataSources used in them. Again, pretty straight forward if you have been following MS during the past year.  DataContext – the base class being used by this implementation – appears one of those LINQ Ueber-classes that will give you everything and the kitchen sink. I need to dig through it some more before being able to verbalize more details of its pros and cons.

 

StaticMethods

 

By the way, I decided to add a Reflector snapshot of DataContext, just so you can see there is a lot of work going on and it requires its very own blog post to discuss.

 

DataContext

 

That’s all for App_Code.
Can you see why I would call it a 1.5 tier implementation? But again lets remember this is a prototyping tool.
App_Code is followed by the App_Theme directory containing a skin and some css files. Not mcuh to talk about there.

 

DefaultSkin

 

 

But before skipping this directory completely – I did find an interesting use of the new CSSAdapters that ScottGu blogged about. For the uninitiated reader, CSSAdapters rock. Please follow the links and read up on it. There are oh so many detractors of MS and Visual Studio pointing out how ASP.NET doesn’t produce the best HTML / CSS based code. One of the favorites has been to – rightly – point to the use of tables in things like menus. Well, css adapters let you switch from tables to divs or ul’s as much as your heart desires, without needing to change the server control code that writes the htnl out in the first place. I love it. Here is a snippet of the css that drives this. By itself its boring but when you think of the possibilities that come with CSS Adapters it does get much more interesting.

 

MenuStyle

 

  

That’s it. We’re down to the actual pages themselves. Again, the entire app is very declarative and here is what one of the aspx pages looks like.Overall this approach is very true to the data access / control enabled coding style that MS has been provided ever since VB3. You get some data and wire it directly into the controls who take care of everything for you. Overall I think that LINQ definitely has its place in my toolbox and I do love how fast I can get a prototype up with Blinq ….BUT (and this is very important) – NEITHER TECHNOLOGY SHOULD BE VIEWED AS A SUCCESSOR TO PROPER OO DESIGN. You will read all sorts of pronouncements, as usual when MS comes out with new versions of tools and code. Please take them with a grain of salt. I do appreciate all the work Polita Paulus has done here. Bravo! There is a true need for this sort of thing, but I also hope she joins me in cautioning the eager developer who thinks he can punch out an app in a minute and have it be the equivalent of Frans’ LLBLGen,  Rocky’s CSLA – or even my own framework NGPF for that matter (shameless plug)  – as well as many more that provide the foundation of solid architecture.

 

 

ExamplePage

 

Comments

Comment from Polita
Time June 29, 2006 at 1:56 pm

Thomas, thanks for the great review!

I agree that we have some work to do (with both LINQ in general and the Blinq web form generation tool) to work out the right way to promote an n-tier data design. In the current previews of LINQ, the best answer to promote encapsulation and limit unwanted access to data from upper tiers is to call ToList() on the IEnumerable returned by LINQ calls, which works but isn’t that elegant and may have performance implications. Both my team (the ASP.NET team) and the LINQ teams are working on finding the right solution for that problem. Worry not; we still believe in the n-tier model. :)

Blinq itself is meant as a prototype for the VS-integrated web page generator we are planning for the next version of Visual Studio. With better integration, you can imagine many more improvements to what Blinq does today. It’s great to get feedback like yours so we know what’s most important to our customers before we ship.

-P

Comment from Thomas Wagner
Time June 29, 2006 at 5:26 pm

Thanks for the comment Polita. Truth be told, I am trying to make sense of the new directions of ADO.NET and I am still not sure where it fits. Maybe if some of the ORM guys in the community post comparative analysis I may get a better understanding. At the moment my framework called NGPF utilizes a domain object approach so its a tad removed from all that new fancy stuff you guys are coming up with :)

Write a comment

You need to login to post comments!