To pass a CancellationToken to dapper, create a “CommandDefinition` Snippet await conn.QueryAsync(new CommandDefinition(procedure, p, commandType: CommandType.StoredProcedure, cancellationToken: cancellationToken));
Old piece of code I had to hunt out today, builds selector to the passed in element /* Get the jquery selector for the specified element */ jQuery.fn.getPath = function (removeClasses) { if (this.length != 1) throw ‘Requires one element.’;…Continue Reading →
I’ve been using a lot of :before and :after recently to add FontAwesome icons to items for visual display and need an icon to display only when an attribute is not empty. Repeating the selector inside a not achieves this…Continue Reading →
Sometimes you need a simpler version of an object with only a few properties. You can manually ignore properties but this can be long winded on bigger classes. In AutoMapper 5 you can pass in the destination type in the CreateMap consructor…Continue Reading →
Snippet /// <summary> /// Create a datatable from a list of ExpandoObjects /// </summary> /// <param name=”list”>The list can be created from a dictionary with Dictionary.Values.ToList()</param> /// <param name=”tableName”>Name of the data table</param> /// <returns></returns> public static DataTable ToDataTable(this List<ExpandoObject> list, string tableName) { if (list == null || list.Count == 0) return null; //build columns var props = (IDictionary<string, object>)list[0]; var t = new DataTable(tableName); foreach (var prop in props) { t.Columns.Add(new DataColumn(prop.Key, prop.Value.GetType())); } //add rows foreach (var row in list) { var data = t.NewRow(); foreach (var prop in (IDictionary<string, object>)row) { data[prop.Key] = prop.Value; } t.Rows.Add(data); } return t; }
/// <summary> /// Converts a DataTable to a dictionary. (NON PERFORMANT) /// </summary> /// <remarks> /// This method is usually used when running dynamic sql in databases that don’t support /// stored procs. The columns returned are unknown so we…Continue Reading →