December 2012 - Digital Tool Factory blog December 2012 - Digital Tool Factory blog

The Digital Tool Factory Blog

How to fix problems with entity framework decimal precision

The Problem

You are attempting to change a database column of type decimal from a precision of two decimal place to one decimal place via data annotations, and there does not seem to be a good way to do it.

The Cause

There isn’t a good way to do it.

The Solution

However, there is at least one non-elegant way to do it – in your OnModelCreating code in your data context, enter in the following piece of code

protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
{
modelBuilder.Entity().Property(xx=>xx.Handicap).HasPrecision(12, 1);
base.OnModelCreating(modelBuilder);

}
The “HasPrecision” part is the key – the second parameter is the number of decimal places to use


12
Dec 12


Written By Steve French

 

How to order a custom WordPress Post Type by a custom numeric field

So, you need to order a custom WordPress Post Type by a custom numeric field – how?

The Problem

You have a WordPress custom post types, and you need to order by a custom numeric field – how do you do that?

The Cause

You would think that it would be relatively simple, for example the below should work

<?php $loop = new WP_Query( array( 'post_type' => 'staff-member',
'posts_per_page' => 100, 'order' => 'ASC', 'orderby'	=>
'meta_value', 'meta_key' 	=> 'OrderByField','type' => 'numeric' ) ); ?>

But ‘OrderByField’ is treated as a text field, and the number 10, comes after 1, not 2.

The Solution

Use the magic keyword meta_value_num, so your WP_Query would look like this

<?php $loop = new WP_Query( array( 'post_type' => 'staff-member',
'posts_per_page' => 100, 'order' => 'ASC', 'orderby'	=>
'meta_value_num', 'meta_key' => 'StaffOrderBy',
'type' => 'numeric' ) ); ?>
the _num makes all the difference - WordPress will treat it as a numeric field.

04
Dec 12


Written By Steve French

 

How to fix problems with asp.net mvc 4 javascript bundling

The Problem

You are using the new JavaScript bundling and minification features in asp.net mvc 4, and some of your JavaScript files are not being included

The Cause

The minification process – in it’s strange wisdom, does not include .min files when it bundles.  Therefore something like

.Include(“~/Scripts/jHtmlArea-0.7.0.min.js”)

will not be included, leading to JavaScript errors.

The Solution

Just use the non-minified version of the script file –

.Include(“~/Scripts/jHtmlArea-0.7.0.js”)

will work just fine – it seems that the asp.net mvc bundler prefers to do it’s own minification.


04
Dec 12


Written By Steve French

 




Copyright 2011 Digital Tool Factory. All Rights Reserved. Powered by raw technical talent. And in this case, WordPress.