-
NHibernate Work-Around is not really a Work-Around... posted on 15 Aug 2011
Over the weekend I came across a blog post about NHibernate, and an apparent work-around for a feature not supported by NHibernate.
The original post can be found here: nHibernate LINQ workaround for System.NotSupportedException
Basically the author wanted to write something along the lines of:
var fruitIds = new List<int> { 5, 8, 13 }; using (var session = factory.OpenSession()) { var result = from f in session.Query<NHFruit>() join i in fruitIds on f.Id equals i select f; foreach (var fruit in result) Console.WriteLine(fruit.Name); }
Where the query joins to a list of Ids to filter the results out. This however, happens to throw an exception:
-
MVC Routing with Attributes makes routing awesome posted on 09 Aug 2011
I evaluated HEAPS of code/libraries and threw in the towel and decided that getting lower-case routes, while still having Area's, was a complete and utter waste of time and effort because they were all crappy, and broke stuff, or didn't work.
That was until my mate Brad grabbed AttributeRouting from Nuget. Oh well you know what, this is the best thing sliced bread.
First and foremost, it solved the number 1 issue I had with routing, lowercase Urls. This is how simple is it to make Routes lowercase.
routes.MapAttributeRoutes(config => { config.UseLowercaseRoutes = true; });
Wow... Yet you bing for lowercase routes, and you end up with strange solutions... Here's a couple.
http://stackoverflow.com/questions/878578/how-can-i-have-lowercase-routes-in-asp-net-mvc
This question links to:
http://coderjournal.com/2008/03/force-mvc-route-url-lowercase/
This breaks Area's, why? Because to handle an Area it appends
?Area=areaname
to the Url. FAIL. Probably worked great for MVC 1,but considering I've seen it linked in MVC 3 questions,I consider it fail. -
Fluent NHibernate - Table Inheritance - Discriminators posted on 08 Aug 2011
So a long time ago James Kovacs posted a article about get/load polymorphism with NHibernate, which was cool and all but I always wanted to know how to map it all in Fluent NHibernate. I worked it out at the time but I guess it's taken me 7 months to write it down.
First up is using a single table, mapping them to multiple classes, this is done using a discriminator. Fluent NHibernate calls this 'table-per-class-hierarchy strategy', which doesn't make sense to me. But meh.
So I'm going to begin with the following classes to demonstrate this:
So if I was to select all WallPost's it would give me instances of LinkShare, and Text wall posts.
These classes are really basic at the moment.
public class WallPost { public virtual Guid Id { get; set; } public virtual DateTime DatePosted { get; set; } public virtual string Title { get; set; } public virtual string Content { get; set; } } public class TextWallPost : WallPost { } public class LinkShareWallPost : WallPost { }
-
MVC +Areas + Routes... Order of Routes Matter! posted on 27 Jul 2011
The order in which routes are registered, really is pretty damn important, otherwise it can have really strange side-effects.
I have a site, which has 3 areas, and no default... 'non-area'.
- Admin
- Members
- Site
So rather than having the structure:
Where the root/default site is in the main directory, with two areas. I wanted this structure:
So no root/default, and just a 'Site' area which would be the default.
Note:The default route is removed from Global.asax... for now
-
NServiceBus Video on dnrTV posted on 19 Jul 2011
Good introduction video on dnrTV with Udi Dahan for getting started with NServiceBus.
It's pretty recent too, June 23rd, 2011.
Udi Dahan on NServiceBus
Udi Dahan shows you how to use the fabulous NServiceBus to provide reliable messaging using both a request/response and publish/subscribe architecture. He shows how much easier it is to use NServiceBus than to use WCF for reliable messaging.
-
Getting Started - NServiceBus with Multiple Startup Projects posted on 11 Jul 2011
I never actually realized this, but one of the things that baffled me was how Udi Dahan, when giving his training, or when playing with the NServiceBus demo's... How multiple projected were started.
It actually made implementing NServiceBus somewhat difficult for me to begin with, because I never knew Visual Studio had a feature to specify multiple projects as startup projects.
If you right click a Solution and go to 'Properties' you are presented with the above window.
In "Startup Project" there's an option to select multiple projects, this solution which is a NServiceBus demo, shows 3 projects set to start.
-
Hide & Show Buttons with Sencha Touch posted on 12 Jun 2011
I'm currently building a demo for work using Sencha Touch mobile JavaScript framework, and needed to change the state of some buttons dependent on which 'card' is shown.
The Doc Api is a little hard to follow in my opinion, but I eventually worked it out.
In hindsight I guess I could have used a single button to do this, but I will demonstrate it with two.
To demonstrate this I'm going to use a Panel, with the buttons to flick between the cards. Instead of using a TabPanel.
So to start with I have a Panel, with a ToolBar docked to the bottom, a couple of buttons, and two cards.
var rootPanel; Ext.setup({ onReady: function () { rootPanel = new Ext.Panel({ fullscreen: true, layout: 'card', style: 'background-color:lightblue;', dockedItems: [ { dock: 'bottom', xtype: 'toolbar', items: [ { html: 'Card 1 Button' }, { docked: 'right', html: 'Card 2 Button' } ] } ], items: [{ html: 'card 1' }, { html: 'card 2' }] }); } });
-
Joining the Windows Phone 7 Club posted on 10 Jun 2011
Yesterday, my new Windows Phone 7 arrived. I ordered a HTC HD7 from eBay, since it's like $350 cheaper than buying it from an Australian retailer. Not only that it seems carriers aren't supporting WP7 too much yet, as two shopped that I enquired about the phone, both tried to talk me out of getting a WP7.
(Photos from http://www.gsmarena.com/htc_hd7-pictures-3338.php)
It's definitely far superior to my iPhone4, after spending a night playing around with it, pretty much everything is better, in my opinion. (I will NEVER hand over money for an Apple product ever again.)
The one flaw that Windows Phone 7 does have, is it's contact. Microsoft really dropped the ball on the contact, or 'People' as they call them. The idea is great, but it lacks the ability to sync contact with outlook with ease. Contact's are synced to... everything else.
-
Refactoring those static method calls for testability! posted on 27 May 2011
One thing I love about working on a legacy application is the weird things I get to problem solve.
A lot of the old system has an awful lot of static method calls, which doesn't leave much to be desired for when it comes to unit testing. I was working on a piece of the system today which is written in .NET 2.0, and is tightly coupled to everything in existence.
I didn't want to go introduce interfaces and wrapper classes in order to abstract out all the dependencies, but I wanted to unit test the work without having to touch the database, which is what these static method calls were doing.
The code I dealt with was something along the lines of...
public class ProductService { public static void Save(Product product) { throw new Exception("This would normally touch a db..."); } }
(Example is completely made up for this blog post and isn't actual code from work)
-
NHibernate Querying for Max value posted on 17 May 2011
Browsing the net today for something to do with Fluent NHibernate I came across a blog post.
http://frankmao.com/2011/01/14/nhibernate-subquery/
The blog post is to do with Subquery, but I got a little bit confused since the post itself doesn't have anything to do with Subqueries.
About the actual post tho, NHibernate.Linq does actually support Min/Max operators.
Infact I just wrote a quick test to see the SQL it generated, the following code:
var result = session.Linq<TestProduct>().Max(x => x.Value);
Generates the following SQL.
SELECT max(this_.Value) as y0_ FROM [TestProduct] this_
NHibernate.Linq has basically been deprecated however since NH3.0 has it's own built in Linq provider, rewriting that query in NH3.0 would look like:
var result = session.Query<BaseClass>().Max(x => x.Id);