Design Pattern Snippets

## Singleton: A singleton stores common data in only one place. public sealed class SiteStructure { object[] _data = new object[10]; static readonly SiteStructure _instance = new SiteStructure(); public static SiteStructure Instance { get { return _instance; } } private SiteStructure() { // Initialize members here. } } =================== Best Practice: Use Lazy<T> to init […]

Using Debounce for Keypress events in Autocomplete

<form> <div class=”status-key”>Type here. I will detect when you stop typing</div> <input type=”text” class=”autocomplete”> <div class=”status-ajax”></div> </form>  Javascript:​ $(document).ready(function(){ var $statusKey = $(‘.status-key’); var $statusAjax = $(‘.status-ajax’); var intervalId; // Fake ajax request. Just for demo function make_ajax_request(e){ var that = this; $statusAjax.html(‘That\’s enough waiting. Making now the ajax request’); intervalId = setTimeout(function(){ $statusKey.html(‘Type here. […]

Database versioning (DB Lifecycle Management)

The state-driven approach is good for projects with a lot of logic in the database and a large team working on it. You are also better off choosing it for small projects that are not in production yet. The migration-driven approach is a better choice in all other cases Summary Article:  ​http://enterprisecraftsmanship.com/2015/08/10/database-versioning-best-practices/ ​State based vs […]

SQL EXCEPT and INTERSECT

— AdventureWorks DB SELECT ProductID FROM Production.Product INTERSECT SELECT ProductID FROM Production.WorkOrder ; ==== Gives ONLY matching ProductIDs.. SELECT ProductID FROM Production.Product EXCEPT SELECT ProductID FROM Production.WorkOrder ; –Result: 266 Rows (products without work orders) ==== Gives ProductIDs from Left Set which are NOT in the right Set.

Best Entity Framework Reference Concise Tutorial

EF6  ​http://www.entityframeworktutorial.net/entityframework6/introduction.aspx EF5 http://www.entityframeworktutorial.net/EntityFramework5/entity-framework5-introduction.aspx​ EF Version History and Features links https://msdn.microsoft.com/en-us/data/jj574253.aspx​ EF querying approaches: http://www.entityframeworktutorial.net/Querying-with-EDM.aspx ## LINQ to Entities: context.Students.where(s => s.StudentName == “Bill”) ## Entity SQL: string sqlString = “SELECT VALUE st FROM SchoolDBEntities.Students ” +                     “AS st WHERE st.StudentName == ‘Bill’”; var objctx […]