St. Louis Day of .NET 2011 – LightSwitch and MVC

This is part of a series of posts containing my notes from the sessions I attended at the 2011 St. Louis Day of .NET conference. 

This series does not attempt to give complete accounts of the information presented in each session; it is just a way to capture the bullet points, notes, and opinions that I recorded while attending the conference.  I have previously posted a list of all of the session materials and sample code that I have been able to find online, so if you are looking for a more precise account of a session, try looking there.

The Keynote session of this year’s conference focused on Visual Studio LightSwitch.

  • LightSwitch SKUs:

    Visual Studio LightSwitch: $299
    MSDN Customers can add LightSwitch to existing versions of Visual Studio at no additional cost

  • LightSwitch creates out-of-browser Silverlight applications.
  • .NET 4.0 is required
  • LightSwitch creates a "model" of an application, which is compiled to a working assembly.  Code doesn’t really exist, at least in the form that it does in traditional .NET applications.  (Unanswered question:  How can a LightSwitch application be extended?  It sounds as if it can only be done within the LIghtSwitch environment.  If the code does really exist, then there’s nothing to pick up and move to a traditional Visual Studio project.)
  • LightSwitch comparisons to Access are very valid, IMO.
  • LightSwitch can present the user with interfaces to build a UI based on the tables in an existing database.  I remember watching non-database-savvy end users attempting to build reports on dBase twenty years ago; those attempts were failures because of the users’ lack of relational database knowledge.   The LightSwitch UIs look like yet another failed attempt to build reports/UIs on top of databases.  End users still need to understand relational databases.  This is still not a solved problem, IMO.
  • To allow for greater extensibility, MVVM applications are created by LightSwitch.  (Unanswerd question: How does this statement make sense if no code really exists?)
  • LightSwitch applications can be deployed to IIS/SQL/Azure.

I attended several sessions focusing entirely or in part on ASP.NET MVC.  I’ve previously written about my disappointment in these sessions, so I won’t  identify the specific sessions or speakers (I’m not trying to call anyone out).

  • jQuery and Microsoft AJAX libraries are available by default in MVC applications.
  • When building a MVC application, you can create an "empty" or "Internet" application.
  • No viewstate or server-side controls.
  • Can create view/controller without a model (use this for About pages, ect)
  • Can customize the view engine; Razor is the default engine.
  • Naming of controllers (and other entities) is important… routing (and other things) expects entities to be named a certain way.
  • Simplest example of a model class is a class with properties for each field.
  • You must create controller to access views.
  • Visual Studio allows creation of views based on an existing model.
  • For simple applications, consider putting logic into the model class(es).
  • ViewBag is used for passing information between controller and view.
  • Because there are no server-side controls, you WILL write lots of Javascript when using MVC.
  • Use Javascript/jQuery to enhance/improve the build-in validation features.
  • Entity Framework 4.1, and Modernizr packages are installed by default.  (Presumably Modernizr is added if you select the checkbox to include HTML5 support.)
  • Another example of how naming of objects is important… RedirectToAction(<name>) method redirects to view named <name>.
  • View templates allow quick builds of pages based on models.  Examples of templates are List and Edit.
  • PluralSource videos on ASP.NET web site are great MVC training material.
  • Controllers contain logic and pass information between model and view.
  • Controller templates help to generate the appropriate controller classes for views and models.
  • In order for WebForms and MVC to work together, you need to be on the more recent ASP.NET engines (for example, the routing engine is important to MVC, so it needs to be available).
  • Back button issues remain; MVC by itself doesn’t mitigate those.
  • Unanswered question:  How do session variables work with MVC?
Advertisements

Updating My Dev Environment: VS2010SP1, MVC3, EF4.1, and NuGet vs the Web Platform Installer.

Earlier this week I realized that I had let the development environment on my laptop get a bit out of date.  Sure, it was running Visual Studio 2010, but I had not applied Service Pack 1, nor any of the big buzzy out-of-band add-ons from the first half of  2011.

So, I sat down to install Visual Studio 2010 Service Pack 1, ASP.NET MVC3, Entity Framework 4.1, and the Nuget package manager.  I learned a few things along the way.  Following is a recap of the upgrade process, along with some notes about what I know now that I didn’t know before.

Step 1) Install Visual Studio 2010 Service Pack 1.  This installation was a painless hands-off procedure, although it did take 2-3 hours to complete.  My dev tools are set up in virtual machines (one for Visual Studio 2010 and related tools, one for WAMP platform tools), so running the upgrade against the virtual machine probably slowed things down.  Regardless, it was a lengthy install.

Step 2) Go to nuget.org and install the NuGet Visual Studio extension.  Again, this was painless; I downloaded the installation package, chose Run, and that was it.  NuGet is a package manager for easily installation and updating of open source libraries and tools in Visual Studio.  Package managers are already popular in other environments, but are a relatively new addition to the Microsoft development stack.

Step 3) Start Visual Studio.  So far, so good.

Here is where things started to go awry.  My own fault, as you will see.  I followed the instructions found at http://docs.nuget.org/docs/start-here/Using-the-Package-Manager-Console to attempt to install the latest versions of ASP.NET MVC and Entity Framework.  I could have just done this via the usual download-and-install process, but I wanted to give NuGet a spin.

Step 4) From the Tools menu, use NuGet by selecting Library Package Manager and then clicking Package Manager Console.  This opens a PowerShell dialog within Visual Studio.

Step 5) Type "get-help NuGet" to view all of the available NuGet commands.

Step 6) Type "Get-Package -ListAvailable" to view a list of all available NuGet packages.  Locate the “Entity Framework” package in the list.

Step 7) Type "Install-Package Entity Framework".  Oops… FAIL. I received the following error:

    Install-Package : The current environment doesn’t have a solution open.
    At line:1 char:16
    + Install-Package <<<<  EntityFramework
        + CategoryInfo          : InvalidOperation: (:) [Install-Package], InvalidOperationException
        + FullyQualifiedErrorId : NuGetNoActiveSolution,NuGet.PowerShell.Commands.InstallPackageCommand 

What I’d uncovered was a fundamental misunderstanding on my part about what NuGet does.  My desire was to add capabilities to Visual Studio itself, not just to a single project or solution.  Turns out that’s not what NuGet is for. 

Step 8 ) Type "get-help Install-Package" to get more information about what I had just attempted.  Included in the description of the “Install-Package” command is the statement "Installs a package and its dependencies into the project."  Ok then, that confirms it… NuGet is for individual projects, not for the development environment as a whole.

My initial misunderstanding of NuGet stems from my only previous Package Manager experience, which was with the “apt” system that is a part of Ubuntu Linux..  Using that Package Manager, I was able to add capabilities and tools to the operating system… things like MySQL and Apache.  This, in fact, is somewhat similar to the Web Platform Installer from Microsoft.  But not NuGet.  NuGet is actually more like RubyGems, which are used to adding capabilities to software projects written in Ruby. 

So, I learned some useful information, but as far as installing ASP.NET MVC and Entity Framework, it was back to the drawing board

Step 9) Shut down Visual Studio.

Step 10) Install ASP.NET MVC 3.  Speaking of the Web Platform Installer, I hadn’t used it a while, so I decided to go that route to install ASP.NET MVC 3.  I browsed to http://www.microsoft.com/web/gallery/install.aspx?appid=MVC3, and clicked Install Now.  The Web Platform Installer itself installed first, followed by ASP.NET MVC 3.  This took much longer than expected to install.  Overall, though, Web Platform Installer was as painless to use as I remembered.  Nice.

Step 11) Install IIS Express 7.5.  Though not part of the original plan, I decided to also install IIS Express 7.5.  I did this using a "normal" download-and-install procedure.  Easy.  As advertised, very lightweight.

Step 12) Install Entity Framework 4.1.  I did this via the download-and-install process (choosing to "save" and then run the downloadable installer… Web Platform Installer was not used).  This installation was very quick when compared to MVC3.  I’m not sure if that was due to the NON-use of Web Platform Installer to install EF, or if EF is simply a much more lightweight install than MVC.

While looking for the correct Entity Framework 4 installer package I noticed the following statement on the ADO.NET blog: "Note: The NuGet package only includes the EF 4.1 runtime and does not include the Visual Studio item templates for using DbContext with Model First and Database First development." So, that provides further clarification that NuGet adds the necessary run-time libraries to specific projects, but does NOT add full development tools to VS.

Step 13) Start Visual Studio and verify all installs.  To confirm that everything was as it should be, I checked the following:

    Step 13a) File/New/Project shows ASP.NET MVC3 Web Application as a project type.
    Step 13b) EntityFramework 4.1.0.0 shows up as an option when adding a reference to a project.
    Step 13c) There is a new option for Add Library Package Reference when adding a reference to a project.
    Step 13d) On the property page for a a web project, there is a new option for running under IIS Express.

That’s it.  My Visual Studio 2010 development environment is now up-to-date. Along the way, I gained greater insight into NuGet, the hot new Package Manager add-on for Visual Studio  In particular, I learned that if you’re looking to upgrade your entire development environment, and want to use a package-manager type application, Web Platform Installer is your choice.  On the other hand, if you want to add libraries to a project on which you are working, Nuget is the tool to use.

St. Louis Day of .NET 2010

This past weekend was my first time attending the St. Louis Day of .NET, a very nicely executed two-day local conference.  Kudos to the organizers and presenters. 

Following are my notes on the individual sessions that I attended.  I’ve tried to clean these up, but apologies if I’ve misrepresented anything that was presented:

DAY 1 (AUGUST 20)

Separating Concerns with the Model-View-ViewModel (MVVM) Design Patterns – Jacob Adams

  • MVVM got a LOT of attention at the conference.  It seems to be THE hot pattern right now.
  • The purpose of the ViewModel is to provide a view-specific version of the model which contains the state and actions of the view
  • Drawbacks of the MVVM pattern are that 1) there is as yet no standard implementation and 2) it can result in redundant ViewModel code.  Note: Several other sessions that I attended showed specific implementations of MVVM that attempted to mitigate the problem of redundant code.
  • iCommand – An interface, implemented of the ViewModel, that is used by the View to send commands to the ViewModel.  It is available in WPF and Silverlight 4, but not prior versions of Silverlight.  For earlier versions, use a 3rd party library like Prism.
  • iNotifyProperyChanged – An interface, implemented on the ViewModel, that is used to allow the ViewModel to notify the View of changes to the data (the Model).

ASP.NET MVC Quick Primer – Gus Emery

  • Not yet fully baked.  I was surprised at how tightly coupled the Model, View, and Controller seem to be; especially in comparison to MVVM.
  • The current version of MVC is 2.0, with 3.0 in Beta (and promising significant changes).
    There are issues installing on Windows Server 2003.  These issues were not specified; it was simply notes that installation on that platform is not seamless.
  • The Controller handles requests, combines Views and Models, and serves up the results (of combining the View and Model).
  • The Model contains Data and Business logic.
  • MVC 2.0 projects automatically incorporate the jQuery libraries. 

SharePoint Server 2010: Getting Started with New Features for .NET Developers – Robert Fischer

  • This session turned out to be exactly what I was looking for; an overview of the SharePoint platform for developers who have never used it before.
  • With SharePoint 2010, standalone installations are possible on 64-bit versions of Windows Vista and Windows 7.  Previously, a server OS was required, making the tool difficult to approach for a beginning developer.  The caveat: installation on Vista/Win 7 is tricky.  Expect to spend at least a day getting it set up.
  • Microsoft offers Virtual Labs as an alternative to a local install.
  • Key initial concepts for beginners are Lists, Content Types, Site Definitions, and Features.
  • Additional important features are SharePoint Designer, Web Parts, and Powershell.
  • Business Connectivity Services allow developers to integrate external data with SharePoint.  It allows for reading and writing to databases, WCF, and data services.
  • There is a lot of functionality that is enabled via point-and-click programming (an example given was reading/writing to a database).
  • While debugging a SharePoint add-on, the solution is deployed to the server for testing, and then automatically retracted when the debugging session is complete.
  • The presenter suggested that large enterprises are replacing their built-from-the-ground-up websites with sites built on top of SharePoint.  He suggested that ASP.NET programmers should learn SharePoint, because the bare-metal ASP.NET sites would be going away.

DAY 2 (AUGUST 21)

JumpStart: DotNetNuke Module Development – Christopher J. Hammond

  • Not exactly what I was looking for, but that was my fault for not reading the session overview closely enough.  I was looking for an overview of DotNetNuke itself, rather than an overview of module development.  Still, it was interesting to compare module development in DotNetNuke with the little I know about module development in Drupal.
  • The recommended setup is for each developer to have an instance of DotNetNuke (including the database).
    For module development, the source code for DNN is not necessary. Only the running application is needed.
    DNN itself is not a web application (pre-compiled), it is a web site (on-the-fly compilation).  Modules can use either model.
  • Virtually everything in DNN is a user control (ascx).
  • Modules will work with the version of DDN on which they are compiled, and on any future version.  They are not guaranteed to work with older versions of DNN.
  • Modules should catch and handle exceptions so that they do not crash the entire container page (and any other modules on that page).
  • A file named module.css contains the style settings for the module.  It must not be renamed.

Building Backward-Compatible HTML5 and CSS3 Applications in .NET – Nik Kalyani

  • Nice overview of the coming features in HTML5 and CSS3.  However, the best information shared was a working example of a HTML4/CSS2 table-less form layout.
  • Code samples available at www.kalyani.com.
  • Modernizr.com provides a javascript library for sniffing browser compatiblity with HTML5 features.
  • Multiple video formats can be listed within the new <video> tag.  The browser will choose the appropriate format to render.  The Flash <Object> tag can also be included within the <video> tag.  HTML5-compliant browsers will ignore it in favor of one of the other formats listed, and older browsers will ignore everything EXCEPT the Flash <object> tag.
  • The HTML4/CSS2 table-less forms example is an example of semantic web markup.  It used CSS and following tags to render a form:  <fieldset>, <legend>, <ol>, <li>, <label>, and <input>.
  • CSS frameworks like Blueprint, 960 (?), and YUI were demonstrated.  Personally, I prefer using CSS without a framework.

Dependency Injection: Don’t Leave Home Without It – Perry Simeroth

  • Disappointing.  This session started well enough, but the second half of the session was dominated by a discussion between the speaker and two or three attendees that questioned aspects of the design pattern.
  • “Code without tests is bad code”
  • “Most applications ignore the last two principles of SOLID, leading to strong coupling and limited testability.

Real World Line-of-Business Development in VS.NET 2010, Silverlight 4.0, and RIA Services – Kevin Grossnicklaus

  • An all-code session in which an application was built from the ground up in one hour.
  • WCF RIA services is a layer on top of WCF that is intended to reduce the complexity of WCF.  Something I should probably pay more attention to.
  • Entity Framework can handle all CRUD applications without the use of stored procedures.  In general, the use of EF 4.0 rather than stored procedures was strongly advocated.

LINQ to XML: A New Way to Parse/Create XML Files – Shawn Mehaffie

  • LINQ to XML can be used to parse CSV files using code similar to the following:

var contacts = from line in File.ReadAllLines(@”contactslist.csv”)
 let parts = line.Split(‘,’)
 select new ContactSimple
 {
  age = parts[0],
  firstName = parts[1],
  lastName = parts[2]
 } 

OTHER STUFF I LEARNED ABOUT

  • HerdingCode podcast – a .NET podcast which I had overlooked
  • Html5Doctor.com – as the site’s tagline says, “helping you implement HTML5 today”
  • Html5Test.com – visit the site and it tests your browser (and assigns a score) for HTML5 compatiblity
  • Book recommendation: “Pro Silverlight 3 in C#”

IF I COULD CHANGE JUST ONE THING

I’d add video recordings of the sessions.  It would be great to be able to watch the sessions you missed.