In C# Getting the Constant Value from Class using Reflection need not be a difficult and there are quite few articles and blogs written on the subject. I wanted to mimic the GetNameQuery function that is in Hibernate, maintaining backward compatibility while converting services to C# using Dapper. For Inspiration I looked at this blog. This returned a list of the constant Names and what I actually wanted to do was look through all the constant names and then match mine and return the Sql value inside.

Where to start: reflection

Firstly we need to look at the FieldInfo Class looking at the example it shows us how we can get the field values.

Read Full Article

Creating Dapper entities using MSSQL and Mapping classes is rather easy, but very time consuming from scratch. This came around because I really got tired of the typing a multitude of class and mapping files So let’s jump into it.

Firstly, lets go get the list of tables, this will return a list in the correct format for the T-SQL in clause. The reason why I did it this way was because it’s easier to remove those that I don’t want to generate entities for.

DECLARE @db varchar(50) = 'Your_db_name'
DECLARE @tempTable Table (TableName varchar(250))

Select distinct '''' +  ltrim(rtrim(t.table_name))+ ''',' as table_name
FROM     information_schema.columns c
         INNER JOIN information_schema.tables t
           ON c.table_name = t.table_name
              AND c.table_schema = t.table_schema
              AND t.table_type = 'BASE TABLE'

Read Full Article

This is just a short post in using Dapper ORM to Map column names in Mssql generating c# csharp code.

I had a requirement using Dapper ORM to Easily Map Column Names, problem was that the columns names had Underscores in them and the need to Have uppercase letter at the beginning of each word to conform to naming conventions. The service we are re-writing has numerous mapping tables so it all started out fine doing the tables with only a few columns, but as things cot more intense at 32 plus columns then I needed a better way to do it. MSSQL, to the rescue, I found a method on the web to convert the initial capitalisation for the beginning of each word for the I used this method:

CREATE FUNCTION [dbo].[InitCap] ( @InputString varchar(4000) ) 

DECLARE @Index          INT
DECLARE @Char           CHAR(1)
DECLARE @PrevChar       CHAR(1)
DECLARE @OutputString   VARCHAR(255)

SET @OutputString = LOWER(@InputString)
SET @Index = 1

WHILE @Index < = LEN(@InputString)
    SET @Char     = SUBSTRING(@InputString, @Index, 1)
    SET @PrevChar = CASE WHEN @Index = 1 THEN ' '
                         ELSE SUBSTRING(@InputString, @Index - 1, 1)

    IF @PrevChar IN (' ', ';', ':', '!', '?', ',', '.', '_', '-', '/', '&', '''', '(')
        IF @PrevChar != '''' OR UPPER(@Char) != 'S'
            SET @OutputString = STUFF(@OutputString, @Index, 1, UPPER(@Char))

    SET @Index = @Index + 1

RETURN @OutputString


Read Full Article

Hackerrank – Weather Observation Station 4
I have always loved just killing some time on Hackerrank, doing some challenges. And today was no different, but what was funny about it was I got stumped by one of the stupidest and simplest things under the sun. I really believe in software we should always look for the simplest answer, but in my case I couldn’t for the love of me come up with the simplest answer which is:


However what came out was a rather convoluted attempt: why do we try do something complex when the answer is actually so simple at the end of the day:

	a.cities - a.uniqueCities
	count(city) as cities, 
	count(distinct city) as uniqueCities 
) a;

looking at some of the answers the where submitted afterwards there where a few interesting ones:

select abs(count(CITY)-count(distinct CITY)) from STATION;


At the end of the Day I suppose we all have days where we take something so simple, but then over complicate it.

I guess we have learnt something just by trying


Yesterday, we had a little issue whereby we needed to modify a production APK to work with Integration. So I want describe how to Decompile, Alter and Compile an apk using the Apktool. I have done some decompiling of Android APK’s in the past to learn how people and companies have achieved something. Never did I have to decompile, alter and re-compile an app using the Apktool. I volunteered naturally as this option seemed loads simpler than looking for the original branch source code at that point.

You should have a good compression tool on you machine I prefer Winrar, but you can use anything you wish.

A text Editor, I use Notepad++

At this point I will assume you already have the current JAVA JRE and SDK installed. You will need this for signing the APK. You should also have the Android SDK, for editing & Compiling etc… You will more then likely already have these if you are at this point.

You will need the ApkTool,the latest version can be downloaded here. The tool allows you to reverse engineer 3rd party, closed and binary Android applications. The tool does this by decompiling / compiling the code using Smali / baksmali. This tool required three files:

  1. apktool.bat
  2. apktool.jar
  3. aapt.exe

Once you have all these tools (not many I know this isn’t that difficult at all), the you are ready to get cracking… I mean reverse engineering.

Read Full Article

In this article I hope to show how to use a Jquery UI dialog prevent / cancel form submission. Based on a work requirement I wanted to stop the submission of a form, so I could validate the some checkboxes using JQuery, if they were all checked the okay button would be enabled and the form would be submitted. This Solution, always for an infinite amount of check boxes to be iterated through and only if all of them are checked will you be allowed to proceed, then it will submit the form as per original. You can check the entire Fiddle here

jquery ui dialog

Service 6

Read Full Article

Something I always forget is when you just want to test a connection or create a connection string, there is this awesome little trick which is part of Microsoft Data Access Components (MDAC) on Windows 2000 and above. The Universal Data Link or UDL (.udl) File. To create the file is as easy as right clicking on the desktop or in a Windows Explorer window and clicking on create New text Document. Right Click on the file again, rename the extension to .udl. Ignore the warning that is shown ” A warning that changing file extensions can cause files to become unusable might appear.”

Read Full Article

We always in inevitability end up with duplicates data where we don’t need it. This is a simple way to find and remove those duplicates. I have documented this procedure for MSSQL 2008 up. Email me if you want the same type of procedure for Databases where you cannot run a CTE (common Table expression).

Finding the duplicates
The first hurdle to success is to find the columns that we can use to determine whether the duplicate exists, this is don’t by writing a query to verify the duplicate Data exists, without that then this is almost a pointless task. In my case It was with a customer Table (Table and Column obfuscated names obviously). Numerous customers had value had duplicate ProfileKey’s, whilst this is only an idea it was critical to avoid duplicates in many systems such as billing and customer management systems.

Read Full Article