Framework Madness!

And other adventures C# and asp.net …

Posts Tagged ‘asp.net

Asp.net Web Forms – A Long Rearrangement

leave a comment »

Dear Asp.net Web Forms,

I have for the most part enjoyed working with you. You have been a good friend, a constant companion, a great enabler. You allowed me to be far more productive than your ancestor, in revision now known as Classic ASP. Even now, right now, as I right this late at night you and I are engaged in a long battle at work – cranking out an eCommerce project using your latest and most greatest features such as Dynamic Data. And yet, even now while we are so closely engaged – I have to admit that your darling first cousin has caught my eye, you know her – ASP.net MVC.

sorcerers-apprentice6[1]You see Web Forms – for all of your power and ease of development, you are not simple to deal with in large projects. Your pattern is fairly rigid – and breaking out is, well, painful. So while am am enamored by all of your curvy controls, you make it hard for me to do what I really want in large applications. And what I want to do is control everything that my app does: I want to easily swap out page views for mobile devices with out configuring multiple web sites, I want my links to be application contextual,  I want to be able to configure any point in the app pipeline, I want to be the master of all routes, and I want to use multiple forms on a page  – please. For all of your programming ease you make this really hard to do, yet MVC makes this easy. And did I fail to mention that I don’t need you to do styles or simulate client events anymore? The browsers have gone and gotten all grown up – and that jQuery guy does some serious kung fu which makes programming cross-browser exponentially easier than it use to be.  Oh – and dude – your HTML and CSS markup up is so late 90’s! I know you know ….

Sure – MVC is not fully grown up and doesn’t have controls yet, if ever. But – it has some great features you don’t and won’t ever have (model binding), it’s taking on a few of your more recent tricks in its forthcoming new version (data annotations and field templates), but most importantly it’s just going to let me make that app I’ve been wanting to make with out all of the crazy hacking you would require (and not to mention the waiting for your next release). It’s not always easy to use MVC, like when trying to make a grid with sorting and paging, but most of it’s ‘magic’ is simple and easily extensible – and Web Forms that’s just not in your make up.

But, were not done yet, and the truth is that hopefully an end is a long time in coming. MVC does take a bit more work to get started, and in some places it just won’t work because it’s not what the customer needs. And it looks like sometimes I will just need you to get along with MVC in the same app. So in the coming months ahead you are just going to have to learn to work side by side. Sometimes Web Forms you will lead, and other times MVC will. But I will need to work with both of you. You’re both valuable. So let’s just call it a rearrangement.

Advertisements

Written by Lynn Eriksen

September 10, 2009 at 4:01 am

Posted in Uncategorized

Tagged with ,

Data Annotations : ASP.net MVC 2 Preview 1

with 4 comments

That title is a mouth full.

Moving on – if you don’t know by now the Asp.net MVC team posted their first draft of v2 last night along with a few blogs posts and a Scott Hanselman Channel 9 video. And while the first hint at Areas looks incomplete, the work on Data Annotations looks very promising.

I have been doing a major eCommerce project at work leveraging ASP.net 3.5 Dynamic Data along with Entity Framework for the admin. Using Dynamic Data has really cut my development time and I couldn’t fathom leveraging MVC without similar support. Well, MCV v2 Data Annotation support thus far appears similar but stripped down like the MCV types like it. Support comes from several improvements:

  • Display and Editor Templates: these are user controls that can be used to create display and editing output for properties specified by Data Annotations applied to the model. These are similar to field templates. However, they can be used for more than just values types, you can make controls for complex types as well.
  • Strong Typed UI Helpers: these extensions of the Html object inside a view not only allow for using lambda expressions for specifying output but also act as the gateway to leveraging Display and Editor templates. And of course using lambda expressions adds compile time support.
  • Data Annotation Validation: model validation now supports data type validations in the controller and returning the same view returns the correct validation error messages.

This really gets my interest in MVC going. The lack of controls is frustrating but I could live with out them. I cannot however live with out Data Annotation UI and validation support so this makes MVC much more approachable in the near term. The rest of the details are in the revised road map.

It looks like future previews will improve on all current features and add a few additional things to boot. How much get’s added to MVC v2 ultimately will be limited by the teams stated goal of being on the  VS 2010 DVD which will probably ship next spring.

More information:

Written by Lynn Eriksen

July 31, 2009 at 6:39 am

Posted in Uncategorized

Tagged with , ,

It was the EF providers. EntityDataSource off the hook.

with 3 comments

The title says it all. It was the EF providers I was looking at that cause my issues when using ‘OrderBy’, ‘Skip’ and ‘Take’ together. It all has to do with how the expression trees are created when using ‘Take’. Let’s look at the two scenarios.

1) Using ‘OrderBy’ and ‘Take’ (no ‘Skip’)

Here is the sample EF query:

TestModel.tblquarantine.OrderByDescending(q => q.MsgDate).Take(100).ToList();

Let’s take a closer look at the execution of this scenario thanks to MySql connector/net source:

  • The ‘Take’ syntax is translated into a DbLimitExpression and placed in the expression tree. 
    (see System.Data.Common.CommandTrees for this and other expression objects listed below)
  • The ‘OrderBy’ syntax is translated into a DbSortExpression and held in the DbLimitExpression’s ‘Argument’ property.
  • The expression tree is evaluated by the provider.
  • After the DbLimitExpression is evaluated to generate sql, the DbSortExpression is evaluated.
  • When the DbSortExpression is evaluated, the DbSortClause objects in the ‘SortOrder’ collection are simply looped over to produce the correct sql syntax.

In both the Devart and MySql providers for MySql the expected sql was returned.

2) Using ‘OrderBy’, ‘Skip’ and ‘Take’ together

Here is the sample EF query:

TestModel.tblquarantine.OrderByDescending(q => q.MsgDate).Skip(100).Take(100).ToList();

This is a very common scenario when  doing paging – and it fails in both the Devart and MySql EF providers. After several rounds at looking at the MySql EF provider source I stumbled upon the problem and the fix for the MySql connector/net provider.

Let’s take a closer look at the execution of this scenario thanks to MySql connector/net source:

  • The ‘Take’ syntax is translated into a DbLimitExpression and placed in the expression tree.
  • ‘Skip’ syntax is syntax is translated into a DbSkipExpression and passed the argument to the DbLimitExpression instead of a DbSortExpression.
  • This is key – the DbSkipExpression expression contains a ‘Count’ property for determining the number of rows to skip and the same ‘SortOrder’ collection used in a DbSortExpression. So, the DbSkipExpression contains both ‘Skip’ and ‘Order By’ information.
  • The expression tree is evaluated by the provider.
  • After the DbLimitExpression is evaluated to generate sql, the DbSkipExpression is evaluated.
  • In the MySql connector/net source only the ‘Count’ property is being evaluated at present. Evaluation of the ‘SortOrder’ collection is omitted, which cause all sorting to be omitted in the generated sql.
  • The Fix:  when the  DbSkipExpression is evaluated the ‘SortOrder’ collection should be evaluated after the Count property. Doing so adds sorting back to the generated sql. In limited testing this has produced the expected sql in all cases.

Now what was most curious is that this error is present in the Devart and MySql provider, which leads me to suspect that this may be in a bug in a sample provider provided by Microsoft to assist in the roll out of EF driver support. But to be fair, it could also just be coincidence.

My bug report of the MySql bug remains open – but I have filed several bugs and the guys that work in connector/net at MySql are usually really good about implementing fixes if they are appropriate. Curiously, my attempts at reporting same bug in the Devart EF forum, albeit with increasing levels of detail over three posts, have been swiftly dismissed as a “limit with the EF framework” and with questionable links to MSDN articles. As a paying customer of the their product (doConnect professional) and a holder of a masters of science (chemistry) I would expect more of an effort. At least show me that you investigated the issue and that a set of problems will result if you do the suggested fix. Devart – I want to comeback for dotconnect and dbForge fusion again. 🙂 Don’t push me away.

 

BTW – if you use Reflector to look the Microsoft EF sql client provider code they do process the DbSkipExpression’s ‘SortOrder’ collection – though in a more elaborate way.

Time to go to bed. See all you coders soon.

 

Updated 7/9/2009

Looks like Devart implemented a fix that will be rolled into their next driver release!
Much thanks!

Written by Lynn Eriksen

June 27, 2009 at 12:28 am

Posted in Uncategorized

Tagged with , ,

EntityDataSource Paging problems with providers for MySql

with one comment

Last week I was working on a small internal project that involved taking payment info, processing it thru a gateway, and saving to a database. I picked the Entity Framework for general data management and ASP.net Dynamic Data to create my admin. Everything was good.

Snoopy should always be allowed!!!So I have gotten my admin set up quickly (used the XML Asp.Net membership providers on CodePlex – http://xmlproviderlibrary.codeplex.com/) and I’m in the admin and trying to sort test payment records in the GridView. But it will not sort. So I look thru all the settings and everything appears correct. I try to look at the ESQL on the Selecting event but have a hard time finding that. I even eventually switch from dotConnect by Devart to Connector/net from MySql and still the same problem. No sorting – still! I feel like Snoopy in a hospital.

The only solution to get sorting was to TURN OFF AutoPaging – and that may be VERY problematic if database paging is turned off.  I really don’t want to return a large number of records for no reason, and MySQL does have paging support. So I am going to try to find some time to get make a sample project and sit down with Connector/Net, which I can get source for, and try to get at the bottom of it. Not sure when, but I’m hoping this blog post helps keep my feet to the fire.

 

Update: 2009-06-23 at 12:12 pm

Today I was able to confirm my suspicions.

When AutoPage is turned on for the EntityDataSource two commands are issued.

  • The first command looks up to total number of rows.
  • The second command applies the correct paging syntax at the end (for MySql this is ‘Limit start,count’) but the Order By syntax is ignored.

When paging is turned off there is a single command issued with out paging but they ‘Order By’ syntax is generated.

Update: 2009-06-24 at 11 am

Further investigation yesterday suggests this may be a issue with the providers in question or the EF assemblies in the framework, not the entity data source. I will try to investigate further today and post my finding to Microsoft, Devart and MySql.

Update: 2009-06-24 at 1:43 pm

Posted bug reports:

http://bugs.mysql.com/bug.php?id=45723

https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=469985

Also posted to the Devart Entity Framework forum.

Written by Lynn Eriksen

June 22, 2009 at 10:42 pm

Asp.net MVC – Why?

leave a comment »

I have been using ASP.net Web Forms since the 1.0 Beta 2 release in late 2001.  At the time of it’s release ASP.net as a whole eclipsed ASP classic in many ways. But like any technology its was designed to solve the technology of it’s time. However, in recent years many of these solutions that Web Forms solves are no longer problems, and quite often today much of what comprises Web Forms and it’s elaborate control architecture seems … unnecessary. Since ASP.net is really just making the .Net framework available for web page creation many of the functional decisions can be traced to browsers of the day. So what was that environment?

  • IE 5/5.5, IE 5 for Mac, and Netscape for 4.x all had a very different support for html layout and css styling. ASP.net’s controls could adapt html css style output depending on what kind of browser was making the request. This would often result much different html and css being sent to the various browsers, depending on the control in question.
  • The XmlHttpRequest object, the X in AJAX, existed primarily in IE for Windows at the time. ASP.net therefore requires full page post backs, but with the existence of control model that emulated state – that allowed for only one form per page and elaborate sever side control pipeline. If you have ever tried to write an elaborate server control you know.
  • The JavaScript environments varied wildly between the browsers, so ASP.net aimed squarely at a creating a pseudo event-driven environment on the server that would allow for a more consistent programming environment. And sure – some control such as validators supported JavaScript in IE, but ASP.net would transparently run the same code on the server if the browser requesting the page didn’t measure up.

So it was a big win for lots of us developers, upcoming and established alike. That was 2000-2001.

Flash forward six or seven years later and all of the scenarios above can be easily handled by all major browsers on Windows, Mac and Linux either by the browser alone or with the assistance of JavaScript libraries. The success of the .net framework and ASP.net have brought in a bucket load of developers that find .net Framework to be powerful but ASP.net engineered. And those of us that have persisted have learned that simpler is almost always better, test if you want to make a living, and you should only have to write your code once. ASP.net Web Forms wasn’t really engineered for these concerns, so the case for adopting Model-View-Controller as an alternative web platform within ASP.net was born.

Written by Lynn Eriksen

June 22, 2009 at 10:22 pm

Posted in Uncategorized

Tagged with ,

Of OAuth and REST Api’s …

leave a comment »

I recently was working on a project that was leveraging a popular on line service’s api’, and by way of that an introduction into OAuth. I have to admit it was more than a frustrating experience. The two biggest pain points where that 1) the documentation was cluttered with OAuth references and syntax, and 2) no working client API’s could be found for the .net platform. (Note: I did find a .net api linked on their forums, but it was broken because the on line service reserves the right to make arbitrary changes to their contract that renders client API useless.)

So after getting past my initial “I cannot belive they’ve done this” thoughts and digging around I found the OAuth web site and it does feature a C# script for the library implementation. (click here). That made things a bit easier. This script will get you most of the way towards making OAuth method calls with ease. Here are a few pointers:

1) Watch out for token usage. Some method calls will require a login token key to be provided in addition the  consumer key. You’ll want to run this as a separate request before making the method hash and subsequent call.

2) Be careful to make sure you have your http method correct as it is part of the signature.

3) You’ll need to append the hash result as a url parameter after calling ‘GenerateSignatureBase’.

That’s it for now.

Written by Lynn Eriksen

January 12, 2009 at 1:55 pm

Posted in Uncategorized

Tagged with , ,