Archive for December, 2010

C# Dynamic keyword, and how you can use it to help TDD!

Just done some reading on the new dynamic typing stuff in .net 4 and it occured to be you could use this to assist using TDD “Test First” approach, where you write code to test methods that you’ve not yet written.  Unless you stub the method, you get compile errors, however using dynamic, the compiler doesn’t evaluate your call until run time, so your test will actually compile and you will get the expected red cross until you’ve actually implemented your method.  Turns out I’ve been beaten to this conclusion though; check out this post on Peter Gfader’s blog

No Comments

Twitter OAuth Registration

Any app’s you create now which need to post to twitter programmatically, will need to do so using oAuth, for which you will need to register your app with twitter- this can be done @ Once registered you will be taken to a page with your consumer keys (a key value and a secret value)- to get your access token, click the button on the right of that page (a token and a secret) and you should now have all 4 values you need to perform oAuth authentication prior to interacting with twitter.

No Comments

MVC with MVVM using Knockout.js

Previously, on

see “Creating an Order/ Order Details style view using MVC2 & Entity Framework 4″

So following on from my last MVC post I posed my question to Scott Hanselman himself via email, and he took the time to write me a very helpful response;

Interesting solution. Good job getting it working.
Take a look at maybe using some cleaner JS on the client…check out my last podcast on Knockout and check out this demo:
The pod cast he’s refering to is here.  The contacts editor example he pointed me to is exactly what I’m trying to do here.  This implementation would totally resolve my issue as you are no longer binding directly to the entity framework objects- I could instead create simple cut down DTO’s for the sale and it’s associated sale lines and serialise it to JSON then use Knockout (an open source javascript library which deals with clientside binding of UI elements to a data structure, like your ViewModel represented as JSON) to deal with all the client-side binding and editing before posting the data back as JSON.  I shall post again once I have something up and working.

6 Comments Roles and Membership installed to local SQL Express 2008 MDF file

Just had an hour or so’s worth of ball-ache from this issue!  Working on an MVC2 site, i wanted to move the default membership out of the aspnet mdf file and into the sites main MDF file.  This should be a pretty simple web.config change, and a matter of running aspnet_regsql against the database.  I read an article mentioning that you can do this straight from the command line to your MDF file, but I had no success with this method- it simply created another database for me with a name equal to the full path of the database i had requested.  So I found I had to attach my database to my local sqlexpress instance, then run it against that;  so in sql;

EXEC sp_attach_db 'mydb', N'E:\_Dev\5imply\5imply-MVC2\BackOffice\App_Data\5imply.mdf'

Then you can just run aspnet_regsql in the same way you would for any other database; In my example I just wanted Membership, roles and profiles

C:\Windows\Microsoft.NET\Framework\v2.0.50727>aspnet_regsql.exe -S .\SQLEXPRESS -d mydb -A mrp -E

Start adding the following features:




Then once you’re done, you can detach again;

exec sp_detach_db 'mydb'

Also- one other gotcha I found was that I had to do all this using SQL Management studio, having started it using “Run as Administrator”- I’m not sure if this is something specific to Windows 7, as  I would have expected to already be an administrator?  But I spent ages wondering why SQL refused to attach my database- Just kept getting an error “create file encountered operating system error 5″ I eventually ran procmon and found it just didn’t have permisisons to the file under the account it was running under.

1 Comment