Internet Explorer is like

Added by Eric Williams on June 07, 2010 in musings

Internet Explorer is like Wal-Mart, nobody likes it but it is very difficult to avoid.

Read more ...

I Quit My Job And We Are Moving Home To Montana

Added by Eric Williams on May 06, 2010 in musings tech

Today I gave my two weeks notice at the place I called home for what would have been 9 years in November. A small natural gas utility in Portland Oregon called NW Natural. Lots of good memories there and I learned at lot from a lot of very smart and talented people there. As a software developer I think I probably should have tried to exist stage right a few years ago but about that time I should have been doing that I met my wife and had three kids. This was the classical enterprise in every sense of the word and my transition to the new company is going to be quite the change for me. I'm going from 'customer' of the contracting firm to the 'contracting' firm itself.

Who Can Help

With the help of twitter (wow, soak that in for a minute) I've made some networking connections with some folks back home. The single person instrumental in getting my family and I heading due east is Doug Odegaard @dodegaard from intraLogix and Who Can Help.

That all so familiar story of developers getting connected on Twitter that we all know, turned into some Skype calls from time to time and having leads on positions in Montana sent my way.  Just like you find your car keys in the last place you look - a recomendation from Doug turned into a first, second, third and fourth interview which left me with accepting a position as a Geospatial Developer at GCS Research in Missoula Montana.

GCS Research

I'm pretty exited about the new adventures ahead of me. Not working on the same systems year in and year out. Mostly greenfield apps and getting all-chips-in on the ESRI .NET stack with some smart, web and mobile clients.

Now onto the small challenge of selling the house, packing up the wife, kids, dog and cat, moving 600 miles, finding a new place to live and ...

Read more ...

LINQPad with Databases

Added by Eric Williams on April 17, 2010 in LINQPad SQLite

LINQPad is a fantastic free utility from author and C# guru Joesph Albahari. Per the tag line on the LINQPad site "Kiss goodbye to SQL Management Studio!" and I would suggest that if you are a SQL Server Management Studio user and also interested in LINQ that you take the LINQPad Replacement Challenge!

I didn't even know about LINQPad until a few years ago when I got the (then 3.0) C# 4.0 in a Nutshell book. It is one of those companion applications that plays a role in the book text and one of the important hooks between the book and the application is that when you registered your copy of the book with the site you received a code that enabled Autocompletion. Not sure if that is still an option or not.

So what the heck is it already? Well LINQPad is many things. It is an application that will allow you to run LINQ queries against a number of things, Objects, LINQ to SQL, Entity Framework, XML, WCF Data Services (OData), SQLite and MySQL as well as a few others. It has the Snippet Compiler feel where you can write a couple of lines of code and F5 it to see what it does. All around a good LINQ-to-* learning tool.

So show me the code already.

First we need a data store to hook up to LINQPad. Let's have a little taste of SQLite for some sample data. I've download a local copy of SQLite and stubbed up a simple database called MyDatabase.db. SQLite has a command line syntax that you can look into. For the point of this post I started SQLite and used the .Read function and supplied a external file name with the contents of the file below.

Now start up LINQPad and click on the standard Add Connection function. Here you'll see a few nonstandard options, at least from the typical items you'd expect when you 'add a connection' from most other windows developer tools.

LINQPad_ChooseDataContext

If you click on the 'View more drivers...' button you'll find options for other third party LINQPad drivers. In this case we're looking for the SQlite drivers.

LINQPad_Choose_a_driver

The driver install for the SQLite driver was pretty slick and seem less and you'll end up with a third item in 'Build data context automatically' section. Select the IQ driver and the SQLite provider and the location of the SQLite database created earlier.

LINQPad_ChooseDataContext_SQLLite_Driver

Now you have an available connection to execute queries against. For the Visual Studio inclined this is the Server Explorer idea.

LINQPad_Current_Connections

Now for a couple of simple queries. The first one if probably the simplest query you could do. Selecting everything. Notice the handy output display it gives you.

LINQPad_Simple_LINQ_QueryAll

And this one has a simple filter to show how you can limit the data you want to return. Nothing but the serious folks listed here and also notice the SQL tab is selected to show you the SQL that is being executed against the given database.

LINQPad_Simple_LINQ_Query_With_Where_Clause

Hopefully this will give you enough of a taste to want to try it out for yourself.

Read more ...

Stupid Linq Tricks Record Rollup

Added by Eric Williams on April 01, 2010 in Linq So Eric Remembers

I've been in these situations too many times where I've had to receive a logical document and the "text" has been split across multiple items in a list. Most of the time it occurs with databases but I've had to do the same thing with B2B integrations with Xml too.

Before Linq I'd end up with the prototypical foreach code but this last time I need to (re)solve such a problem Linq had since been born.

Here is an example:

Big deal. What if you have a set of data that has multiple comments

Here are the static helper methods I used to kruft up some sample data if you would like to play around with these queries

I do realized that ORM and other database queries have the ability to do these aggregates for you. I was merely trying to point out some Linq tricks for those situations where you are dealing with objects and might not be in a data access situation.

Read more ...

Getting started with MVCContrib Filters

Added by Eric Williams on March 30, 2010 in ActionFilters Asp.Net MVC MVCContrib

What is MVCContrib?  MVCContrib is a open source project was designed to add functionality and ease-of-use to the out of the box experience of the ASP.NET MVC Framework.  It kicks in where MVC on its own has left off.  MVCContrib is hosted on CodePlex at http://mvccontrib.codeplex.com and it also a CodePlex Foundation Project.

In this post I'm going to cover a couple of the Action Filters that are included with MVCContrib, ModelStateToTempData and PassParametersDuringRedirect.

ModelStateToTempData

When you have this filter decorating your action method (or at the controller level) you will get a behavior in which that when model state gets created post model binding you might have a state in which you want available to another action method.  This happens when you are practicing the Post-Redirect-Get Pattern (PRG).

Let's say you have a CustomerEditModel that coming from a web form.  You need a Post Action that takes in a CustomerEditModel and out of the box that DataAnnotations will engage and validate your model.  Below is a model with two attributes, Required and DisplayName.  Required may or may not be what you think it means and DisplayName gives you an opportunity to give your labels a different name than from the reflected property type name when using the template helpers (go read Brad's series now).

Ok back to the story. When you submitted a nice clean valid model and you flow into the ModelState.IsValid block life is good. When you had some validation issues and you flow to the FixErrors RedirectToAction something particular needs to happen. ModelState has some your validation results that you will want to use to display validation hints back to your end users. The problem is that ModelState isn't carried over, without any intervention to the next Action method being called.

Enter the ModelStateToTempData Attribute

Add a [ModelStateToTempData] to the action method that the modelstate is being generated from, let's call it the sender, AND the action method that needs to use it, maybe call it the reciever?

What's happening on the sending side with these attributes is when a RedirectToRouteResult is returned from an action (in this case we're using RedirectToAction) any data that is the ModelState dictionary will be copied into TempData - A.U.T.O.M.A.T.I.C.A.L.L.Y. You don't have to manually do it yourself!

What's happening on the receiving side with these attributes is when a ViewResultBase is returned from an action (in this case we're using View) all the data that was previously put into TempData is copied out of TempData and put back into ModelState

In this case since we're in the FixErrors action the errors that we just got back from the [ModelStateToTempData] attribute will be displayed on the user form. Additionally we're also getting back the values of the "bad submission" from the end user so that for non-trivial (or really any) forms they don't have to re-enter their data.

PassParametersDuringRedirect

Since we live in a perfect world and our information management is so well done that our users get all the forms filled out perfectly that that always drop into the ModelState.IsValid block every time. Maybe we can just render the view from there ... NO! My post, my rules. Thou shalt not render view from Post Methods. We have to PRG our way out of there. In this case we'd do something interesting with some persistence and then we'll take the user to a 'You Are Teh Awesome' page.

Let's take the same controller action methods but add one more attribute to them, [PassParametersDuringRedirect]

I'd like to point out that the difference between the two RedirectToAction call in the CreateCustomer Action Method. The second one, the one that ships with Asp.NET MVC and the first one has the nice expression in there. This is another nugget that comes with MVCContrib. This flavor of the RedirectToAction extension method will take in a an expression and make sure that the destination method will have the correct parameters passed to it.

The new attribute added to the methods, [PassParametersDuringRedirect] is bringing some more pleasant PRG stuff to the controller. After the valid customer has been 'persisted' we want to show the user a Sucess page. In this case we want to show the model (or maybe another model with additional information) thus the method signature as so public ActionResult Success(CustomerEditModel customerEditModel). This is very similar to the [ModelStateToTempData] behaviour.

I hope this information has helped. Just until very recently I didn't know these things were in the MVCContrib project and now I have some code to delete from our current code base.

Read more ...