Rants Tagged with “.NET”

As many of you may have heard, I recently launched http://GiveAQuiz.com as a new web site for creating and taking quizzes. The Data Team at Microsoft were great in helping me build this site. I've written a whitepaper detailing how we used the Microsoft data stack to accomplish it. This whitepaper shows how we used these data technologies to build the site:
If you are using Microsoft's Data stack for your own web-based and/or Silverlight site, give a look...hopefully some lessons learned you can use:
http://msdn.microsoft.com/en-us/library/ff847451.aspx

So my blog has been pretty quiet lately and I thought I'd let you know why. With a small team, I've been building GiveAQuiz.com.
Several months ago I was working with a client who wanted me to put together a short quiz on Silverlight to help determine which of their developers got to join their Silverlight team. So I did what I always do, I searched the Internet for some small startup site that let's me accomplish the task at hand. Unfortunately all I found were logs of 'survey' sites that would let me put together some questions but only receive summary results. The one site I found that would let me build a quiz, only would let me print a PDF of the quiz to give to people by hand. This got me thinking about how a site that let people give quizzes might not only be helpful to people like me, but also to teachers of all kinds. I was determined to create the site...when I had free time (yeah, I know).
As I had chances, I would do some small part of the planning. When I wrote a SketchFlow article, I used the opportunity to prototype some of the screens for the article. But to get the site really built, I needed help. To the rescue came Microsoft and Chris Sells. Chris and I decided we wanted to build the site in the same spirit as NerdDinner.com. Microsoft would help fund the development of the site and I would write a whitepaper and do some videos on how we built the site.
I put together a small team consisting of Chris Rauber (ASP.NET MVC dev extraordinaire), Dennis Estanislao (designer savant) and myself to build this site. The site is now live, but is in a private beta mode (where you can e-mail me to get an account for a limited number of users) until we get the bugs out.
Building the site was a lot of fun and we got to mix a lot of technologies inlcuding:
From the beginning the expectation was to have the source code available under MS-PL so that it could be an exemplar for other developers to see how a site with the latest Microsoft stack. You can find the current version of the source code on CodePlex at http://giveaquiz.codeplex.com. We are accepting new members to help implement new features after launch so if you're interested in helping, feel free to apply on the CodePlex site. We we do a formal release of code once the private beta is complete. We also used AgileZen.com (who graciously granted us a free license since we were working on an open source project) and using it for workflow between disconnected members turned out really well. Love the product!
So now its your turn, I want to ask you my readers to check out GiveAQuiz.com and ask for a private beta account. The first twenty-five people who contact me at "shawn at giveaquiz dot com" will get into the private beta. Help us find the bugs please!

As my continued facination with all things SQL Server Modeling related, I was tasked with writing a short article on the introduction of the basics of SQL Server Modeling for the developer. The result is the article "The Busy Developer's Guide to SQL Server Modeling" that was released on MSDN today. It is short so you can get the big details without investing a month learning the technology. Let me know what you think!
If you've been following my blog, you should know that I am keeping a pretty close watch on ADO.NET Data Services. The team recently released a second CTP of the new version with some interesting features. This CTP has some pretty compelling additions, but I am going ot focus on one in particular.
I've been teaching and using ADO.NET Data Services for a long time and I like showing off exposing a LINQ-based provider (Entity Framework, NHibernate or others) to a Silverlight application. While ADO.NET Data Services does expose its API through a REST API, the magic for me is in its use in Silverlight. In case you haven't been following along, using the Silverlight client you can issue a LINQ query through the Silverlight client (though in fairness, the full power of LINQ is not supported in the client):
var qry = (from g in ctx.Games
where g.Genre.Name == "Shooter"
orderby g.ReleaseDate
select g) as DataServiceQuery<Game>;
qry.BeginExecute(new AsyncCallback(r =>
{
try
{
theList.ItemsSource = qry.EndExecute(r).ToList();
}
catch (Exception ex)
{
// NOOP
}
}), null);
This is a powerful feature so that (unlike web services) developers can use a looser service definition to define their data stack. Let the developer who needs data be able to sort, filter and shape that data as necessary.
The last part of that phrase is "shape" on purpose. When I first teach this technology, I am often asked "what sort of shaping do you mean?" In ADO.NET Data Services 1.0, you could shape it by returning a hierarchy of data using the Expand method in the LINQ query. For example, we can return the game data with the Genre entity attached to every game like so:
var qry = (from g in ctx.Games
.Expand("Genre")
where g.Genre.Name == "Shooter"
orderby g.ReleaseDate
select g) as DataServiceQuery<Game>;
qry.BeginExecute(new AsyncCallback(r =>
{
try
{
theList.ItemsSource = qry.EndExecute(r).ToList();
}
catch (Exception ex)
{
// NOOP
}
}), null);
But this level of shaping is powerful but limited in scope. This is where ADO.NET Data Services 1.5 comes up trumps. In this new CTP we can now do projections to retrieve specific data. For example:
var qry = (from g in ctx.Games
where g.Genre.Name == "Shooter"
orderby g.ReleaseDate
select new
{
Name = g.Name,
ReleaseDate = g.ReleaseDate.GetValueOrDefault(),
}) as DataServiceQuery;
This query creates a new anonymous type that has the two values we want instead of returning the entire entity. In any other .NET project this would be fine, but for Silverlight we can't use the anonymous type for data binding (for security reasons). So like other anonymous type uses in Silverlight, you must project them into a known type. A type like that is pretty easy to cruft up if you need:
var qry = (from g in ctx.Games
where g.Genre.Name == "Shooter"
orderby g.ReleaseDate
select new GameInfo()
{
Name = g.Name,
ReleaseDate = g.ReleaseDate.GetValueOrDefault()
}) as DataServiceQuery<GameInfo>;
This is useful to no only limit the fields you return but also to shape the result. For example we can use the projection to retrieve the name, release date and the genre's name (normally a related object) like so:
var qry = (from g in ctx.Games
where g.Genre.Name == "Shooter"
orderby g.ReleaseDate
select new GameInfo()
{
Name = g.Name,
ReleaseDate = g.ReleaseDate.GetValueOrDefault(),
GenreName = g.Genre.Name
}) as DataServiceQuery<GameInfo>;
This is all well and good, but what about saving these projections? For the most part you should treat complex projections (like the one above) as read-only. But if you retrieve entities that are purely subsets of existing entities, then ADO.NET Data Services will handle it. Though currently this is crashing in Silverlight (it is a CTP after all). I will update this if I find a way around the saving bug in the near future and post the demo at that time.
But in general this is an awesome new addition to the library that I hope will close some of the use-cases that forced me to write Service Operations in the past.
What do you think?

It all depends...
I've spent the better part of six weeks building the new AgiliTrain website and its been quite a lot of fun. Of course if you have been reading this blog for long you know that I usually take a personal project like this as an opportunity to learning something new. In this case I did three things I haven't done on a personal project before:
- Use ASP.NET MVC (Beta)
- Use Oslo's MSchema
- Use a Designer
I've been itching to use ASP.NET MVC on a project but until the beta arrived I didn't want spend too much time with it. Of course as you probably know, ASP.NET MVC released a RC yesterday so its pretty close to being done. I am still on the Beta until they RTW (release to web) ASP.NET MVC. Don't want to retrofit it twice.
I've been thinking a lot about how I would characterize my experience with ASP.NET MVC. I recently was at a talk from Paul Lockwood (at the Atlanta .NET User Group) and he thought that it was two weeks of a steep learning curve then bliss. That's pretty close to my experience. I thrashed for a couple of weeks wondering whether going back to WebForms would be faster...but I was patient.
I talk to some people about their fears of ASP.NET MVC and the big one I hear is lost of ViewState. I was never a fan of ViewState and was always perplexed that most projects used WebControls and not nearly enough HtmlControls. HTTP is stateless so in many many situations remaining stateless makes more sense. Since the HTML controls were lighter weight I tended to use them much more often. That certainly makes my move to MVC easier as I am not bogged down by the loss of ViewState.
Another contention I hear is that ASP.NET MVC allows you to write code more like the web. This means doing a lot of AJAX and using jQuery (or Dojo, or whatever you want) as your UI layer. While that is interesting in a wide variety of scenarios...I don't think PostBacks are as evil as we make them out to be. One of the problems with WebForms was that since it was tied to post-backs and sending back ViewState...those post-backs were always big. For AgiliTrain I didn't feel the need for a lot of wiz-bang. I am just presenting materials and taking data (for registration and such). Very simple and doing that in simple HTML still appeals to me. In fact, the argument against simple post-backs is lost without ViewState. My Postbacks to the server are tiny because they simply contain mostly just the data users are entering. I think the real evil was when post-backs were used as a replacement for event handling situations...the post-backs themselves weren't the problem...the programming model was.
I did use jQuery in a couple of places where I needed rich behavior in the UI but that was the exception rather than the rule. I built a website not a web application. If you're building a web application, this is likely to be reversed. Building lots of interactivity and paging and such makes sense in that case...just not mine.
But why did I use ASP.NET MVC at all? Was it because I wanted to learn a new technology or was it the best tool for the job? In my case both are true. I needed a site that is very SEO friendly and to do the kind of routing I wanted (like I did in my Wildermuth.com site) was harder than it should have been. I wanted a better experience. I also thought that since I was presenting information that is changing somewhat rapidly that I could develop it faster with ASP.NET MVC. Not faster in the initial implementation (because I had to learn MVC) but faster to add new functionality as it required it. I am not positive this is true but in the last few days I've been able to add new pieces of functionality to the site pretty easily. It feels a lot more modular than my other sites.
There were two big ah-ha moments for me in using ASP.NET MVC:
- When I was told to create models that contained the data for the view (instead of using my data model).
- When I integrated the designer's wireframes into the project.
The first of these was big because I was using ViewData for everything and it felt like Session state again. A big property bag of loosely typed data that I was hoping would work.
The second of these was a huge surprise as the MVC code was mostly clean HTML (no magic ClientID's or controls) so that integrating was simple.
In the next couple of parts of this series I will delve deeper into how I built up the site using ASP.NET MVC and why I think its a great approach for my future projects.
If you missed me in Bulgaria's DevReach conference, the video of my Silverlight Data Access talk is now available. The original talk's description was:
In this session, we will explore the different methods for dealing with data in your Silverlight 2 applications including LINQ, ASMX, WCF, REST, Astoria and WebClient calls. The session covers both how to consume data as well as how to expose data to Silverlight 2.
Hope you enjoy it!
I am working on a hybrid ASP.NET MVC and MVC Dynamic Data project. To work on it I started with the MVC Dynamic Data project assuming this would be a Dynamic Data Project and an MVC project. As Scott Hanselman recently posted, you can mix and match pretty easily so the code was working but I was missing an important piece of functionality in Visual Studio:

My project wasn't being showing these items (or other menu options specific to MVC apps). I suspected it was some magic in the project file so I opened it up in my favorite editor:
<Project ToolsVersion="3.5"
DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">
Debug
</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{F7526D86-12B4-434F-8355-20592CFC4937}</ProjectGuid>
<ProjectTypeGuids>
{603c0e0b-db56-11dc-be95-000d561079b0};...
</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Foo.Web</RootNamespace>
<AssemblyName>Foo.Web</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup>
The missing bit was a special ProjectTypeGuid: {603c0e0b-db56-11dc-be95-000d561079b0}. You need to add this to the existing ASP.NET project's ProjectTypeGuid list in the project file and magically the project item types appear.
HTH
Today at 3pm CST (4pm EST, 1pm PST) I will be doing a LiveMeeting talk on ADO.NET Data Services. If you are not at the PDC this week, drop by NotAtPDC.com and check out my session!
I haven't had a chance yet to drop in on the ALT.NET Meetup but i'll be there this Wednesday. If you're interested in pragmatic development or just want to listen in on some of the ideas surrounding ALT.NET, go RSVP and join us at the meet up. As a bonus its a "Thinking Man's Tavern" in Decatur which is a cool little cafe with kick ass food.
Will I see you there?