Skip to content

Instantly share code, notes, and snippets.

View kmoormann's full-sized avatar

Kevin Moormann kmoormann

View GitHub Profile
using System.Collections.Generic;
using System.Linq;
using AutoMapper;
using AutoMapper.QueryableExtensions;
using FluentAssertions;
using NUnit.Framework;
namespace Automapper.PolymorphicList.Tests
{
[TestFixture]
@kmoormann
kmoormann / CSharpDtoBuilder.sql
Last active August 29, 2015 14:14
C# Dto Builder Based On Information Schema
DECLARE @tableName VARCHAR(50) = 'Foo'
SELECT
'public '
+ CASE
WHEN DATA_TYPE = 'int' THEN 'int'
WHEN DATA_TYPE = 'uniqueidentifier' THEN 'Guid'
WHEN DATA_TYPE = 'nvarchar' THEN 'string'
WHEN DATA_TYPE = 'datetime' THEN 'DateTime'
WHEN DATA_TYPE = 'bit' THEN 'bool'
@kmoormann
kmoormann / GetEnumDisplayNameExtension.cs
Created September 4, 2014 20:43
An extension method for C# that will prove a DisplayNameAttribute if available
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace Inventory.Data {
@kmoormann
kmoormann / EqualsSnippet.cs
Created April 24, 2014 02:53
Equals method override snippet
public override bool Equals(object obj)
{
return this.Equals(obj as IAggregate);
}
public virtual bool Equals(IAggregate other)
{
return null != other && other.Id == this.Id;
}
@kmoormann
kmoormann / EnumToSelectListItemExtension.cs
Created April 18, 2014 14:50
Enum to MVC SelectListItemExtension....IN PROGRESS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Inventory.Web.Code.Extensions
{
public enum SelectListItemEnumValueOption
{
@kmoormann
kmoormann / DATETIME2_NVARCHAR_FORMATTER.sql
Created March 20, 2014 17:29
SQL nugget to turn a datetime2 into a NVARCHAR as 'YYYY-MM-DD HH:MM:SS.mmm'
DECLARE @InsertDate DATETIME2
SET @InsertDate = GETDATE()
DECLARE @InsertDateString NVARCHAR(24)
SET @InsertDateString =
CAST(YEAR(@InsertDate) AS NVARCHAR(4))
+ '-'
+ CASE
WHEN MONTH(@InsertDate) < 10 THEN '0'
ELSE ''
@kmoormann
kmoormann / RemoveNULLfromDatabaseOutputFile.fsx
Created September 6, 2013 20:10
An F# script that will remove the string "NULL" from a text delimited file. Often when saving a SQL query result to a file NULL values will be saved as the string "NULL". This removes them so that they are easier to process
open System.IO
let lines path =
System.IO.File.ReadAllLines(path)
let writeFile lines path =
System.IO.File.Delete(path)
System.IO.File.AppendAllLines(path, lines)
let replaceNulls path =
let origFileNameAndExtension = System.IO.Path.GetFileName(path)
--USE <REPLACE WITH DATABASE NAME>
CREATE TABLE #tablesOfInterest (TableName VARCHAR(2000))
INSERT INTO #tablesOfInterest
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME
IN ('table1'
,'table2'
)
@kmoormann
kmoormann / ForeignKeysForSQLDatabase.sql
Created July 26, 2013 15:45
Determine all foreign keys for a sql server database. Tested on SQL 2008 R2
USE <REPLACE WITH DATABASE NAME>
SELECT
foreignKeyConstraintObject.Name as ForeignKeyConstraint
,foreignKeySchema.Name as ForeignKeySchema
,foreignKeyTable.Name as ForeignKeyTable
,foreignKeyColumn.Name as FoeignKeyName
,referencedSchema.Name as ReferencedSchema
,referencedTable.Name as ReferencedTable
,referencedColumn.Name as ReferencedColumn
@kmoormann
kmoormann / SQLServerProductInfo.sql
Created July 12, 2013 20:22
A simple query to determine the SQL Server version level and edition
SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition')