Friday, August 28, 2015

Recompile the store procedure to improve the performance

One of our report runs under 2min in TEST environment, but over 10 min when deployed in production.  After days of research, it turns out all we need to do is to recompile the stored procedure.

Below is from MSDN:

When a procedure is compiled for the first time or recompiled, the procedure’s query plan is optimized for the current state of the database and its objects. If a database undergoes significant changes to its data or structure, recompiling a procedure updates and optimizes the procedure’s query plan for those changes. This can improve the procedure’s processing performance.

USE AdventureWorks2012;
EXEC sp_recompile N'Sales.Customer';

Monday, August 17, 2015

Use camelCasing JSON

Add the following code in the WebApiConfig.cs file in the App_Start folder:

In the Register static method, add:

// Web API configuration and services
config.Formatters.JsonFormatter.SerializerSettings.ContractResolver =
                new CamelCasePropertyNamesContractResolver();


Wednesday, June 17, 2015

Bootstrap Themes

Tuesday, June 09, 2015

MVC bootstrap Modal Dialog

starts with:

Replacing Html.BeginForm with Ajax.BeginForm:

Fix the cache issue with Ajax.BeginForm:

Monday, June 01, 2015

MVC data annotation on Password field

Below is the cheat sheet for the password field:

[StringLength(255, MinimumLength=8)]
[RegularExpression(@"^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^\da-zA-Z])(.{8,15})$", ErrorMessage = "Password must contain at least 1 number, 1 uppercase letter, and 1 special character.")]
public string Password { get; set; }


^                   #Beginning of expression
(?=.*\d)            #At least one digit
(?=.*[a-z])         #At least one lower case
(?=.*[A-Z])         #At least one upper case
(?=.*[^\da-zA-Z])   #A non-alphanumeric character
(.{8,15})           #Allow between 8 and 15 characters
$                   #End of expression

Good website to find a starting point for Regular Expression: