Posts

Showing posts from 2016

TypeScript - keeping compiled files in a separate directory

Image
When we use TypeScripts in visual studio projects, the compiled JavaScript (.js) files generated from the TypeScripts (.ts) are saved by default in the same directory where the ts files are located. Sometimes it could be annoying for example: if we want to ignore the compiled js files from source control. We can separate the directory for the compiled files very easily with a simple project setting. Lets say we have a folder structure in a visual studio solution as in below: As you can see, we have different folders for different modules inside our script folder and I've added the "js" folder to put all the compiled javascript files inside it so that I can ignore them from source control. To do this, I've changed the "TypeScript Build" settings (using Visual Studio 2015) from the project properties dialog: Notice that I've checked to redirect the JavaScript output to a directory. If you don't want to generate mapping files, you should u...

Creating transformations for custom config files

Image
Visual Studio provides native support to add application config transforms. But it is restricted to the native configuration files only. Also by default it only provides transforms for debug and release environment. If you need to use your own custom configuration file for custom defined environment, below are two options you can follow: Option 1: Do it "manually" Let's assume, we have a configuration file: Configuration.xml in a project. We want to add Configuration.Staging.xml and Configuration.Production.xml as transforms. To achieve this, I can add those xml files manually first and then edit the project file (.csproj) as below and then re-load the project: <ItemGroup>     <Content Include =" Configuration.xml " >        <SubType> Designer </SubType>        <TransformOnBuild> true </TransformOnBuild>        ...

System.TypeAccessException: Named type "CustomGrainState" is invalid: Type string "CustomGrainState" cannot be resolved.

Image
Sometimes Orleans throws the following exception when it fails to serialize a custom object: System.TypeAccessException: Named type "Simple.GrainImplementation.CustomGrainState" is invalid: Type string "Simple.GrainImplementation.CustomGrainState" cannot be resolved. at Orleans.Serialization.BinaryTokenStreamReader.ReadSpecifiedTypeHeader() at Orleans.Serialization.SerializationManager.DeserializeInner(Type expected, BinaryTokenStreamReader stream) at Orleans.Serialization.BuiltInTypes.DeserializeOrleansResponse(Type expected, BinaryTokenStreamReader stream) at Orleans.Serialization.SerializationManager.DeserializeInner(Type expected, BinaryTokenStreamReader stream) at Orleans.Serialization.SerializationManager.Deserialize(Type t, BinaryTokenStreamReader stream) at Orleans.Serialization.SerializationManager.Deserialize(BinaryTokenStreamReader stream) at Orleans.Runtime.Message.DeserializeBody(List`1 bytes) at Orleans.Runtime.Message.get_B...

Collection of frequently used SQL

I have gathered some SQL queries and commands frequently used by developers (like me ☺) to reduce the googling time. For quick reference query titles are enlisted below with links: Commonly Used Queries Get all columns with specific name Get all connected tables Get all foreign key reference of a specific table Get all foreign key references of a specific column of a table Search across all tables for specific value Some Useful Syntax Get data with pagination Rotate data (PIVOT and UNPIVOT) Using common table expression (CTE) Ranking Data Get values from XML column Some Useful Commands Get database server information Get all database names Commonly Used Queries Get all columns with specific name This query could be useful when we've got a column name, but don't know which table it belongs to. -- Find All Columns From All Tables With Similar Name SEL...

Converting SQL query result into JSON string

Image
SQL doesn't provide native support to translate query result into JSON format. But we can achive this with a little twisting with SQL :). Assume we have a "Computer" table in database with the following data: Now, we can get this data into JSON format using the query below: Here, I've used UNPIVOT operation to de-normalized the data and then constructed the JSON string. Notice that: the ProductCode has been used as the primary key of the objects in this query. You can also achive the same thing without using UNPIVOT; but in that case you have to construct the JSON string for every column you need by yourself. And if you are looking for more generic one to convert each row from a data set regardless of any primary key or without knowing the exact columns to be converted, following stored procedure could be helpful: I hope this will be helpful to someone looking for generating JSON feed directly from SQL. Cheers!