LINQ tricks for performance (LINQ2SQL Old School)

I’m working quite a bit on the new Silicon Valley Code Camp site these days and introducing lots of new ways to view sessions.  Much of this code I’ve written over 8 years ago, long before I had so many tricks in my bag. So, one of the things we track is session interest by attendee.  To do that we have two tables, SessionAttendee and Sessions. Doing a simple join and count of the number of SessionAttendee records per session pretty much gives us what we need. Basically, we create a dictionary so we can get all the counts at once so that way, just one sql to the database interestCountsDict = (from data in meta.SessionAttendee where data.Interestlevel == 2 group data by … Continue Reading

Collection Form Post Parameters in WebAPI Controller

There are lots of ways using ASP.NET MVC4 to collection passed in form parameters (POST) to the WebAPI Controller.  I’m not wanting to create a Model, I’m not wanting to get involved with dynamic variables, I just want the values that are posted in.  Say for example, my post looks like the following: To capture both sessionId and trackId, I can have a WebAPI controller in Visual Studio that looks just like this: namespace WebAPI.Api{ public class SessionRpcController : ApiController { [HttpPost] [ActionName("UpdateSessionTrack")] [Authorize(Roles = "admin")] public HttpResponseMessage PostUpdateSessionTrack( FormDataCollection formDataCollection) … Continue Reading

Simple DropDownList With Default Value Using ASP.NET MVC4, Razor and an HtmlHelper

First, the results of what you get.  Notice the URL parameter, the default value in the DropDownList and also the text value output on the page.   Visual Studio Project Background I know a lot of us are struggling changing from ASP.NET WebForms to MVC4.  For me in particular, it’s been a struggle but I’m slowly seeing light at the end of the tunnel.  Our Silicon Valley Code Camp has been in the process of rewriting in MVC4 for the past many months, and with the help of contractors (and me), we are getting there.  Basically, the site has gone from: to The example I’m showing here is really based on just implementing a tag cloud manager. You can see an example of this in production and in … Continue Reading

Using Visual Studio 2012 Web Publish For Staging On The Internet

  Let’s say you have a production code like and you want to have a test site on the internet that will not be seen by anyone unless they login (or maybe even login as an admin).  Using web.config (with Visual Studio 2012), transformations makes that very straight forward.  I know because I just did that.  I created a test site (say: and set up my publish to replace my normal anonymous authentication (allowing anonymous users) to one that denies anonymous users.  Just as an aside, the reason I did this was I notice that google was indexing some of those pages even though my robots.txt file says to deny access to all robots.  Apparently … Continue Reading


Get every new post delivered to your Inbox

Join other followers: