This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Calculates the dependencies between database tables in a SQL Server database | |
-- to assist with writing a script to clear data from a set of database tables. | |
-- This works in SQL Server only. The information schema views follow an ISO | |
-- standard and this script could probably be adapted to another platform fairly easily. | |
-- 1. Get the tables that we want to clear data from. We're restricting ourselves | |
-- to a single schema here. To support multiple schemata we'd need to track | |
-- schema names along with table names. Is it common to have foreign key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Calculates the dependencies between database tables in a SQL Server database | |
-- to assist with writing a script to clear data from a set of database tables. | |
-- This works in SQL Server only. The information schema views follow an ISO | |
-- standard and this script could probably be adapted to another platform fairly easily. | |
declare @crlf varchar(2) | |
set @crlf = char(13) + char(10) | |
-- 1. Get the tables that we want to clear data from. We're restricting ourselves |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const string ResetSql = @"delete from a | |
delete from b | |
... | |
delete from m"; | |
// Removes any data generated by tests from the database | |
private void ResetDatabase() | |
{ | |
InUnitOfWork(session => | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DELETE FROM ... | |
IF EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Customer_Customer_MergedToCustomerId]') AND parent_object_id = OBJECT_ID(N'[dbo].[Customer]')) | |
ALTER TABLE [dbo].[Customer] DROP CONSTRAINT [FK_Customer_Customer_MergedToCustomerId] | |
DELETE FROM [dbo].[Customer] | |
ALTER TABLE [dbo].[Customer] WITH CHECK ADD CONSTRAINT [FK_Customer_Customer_MergedToCustomerId] FOREIGN KEY([MergedToCustomerId]) | |
REFERENCES [dbo].[Customer] ([CustomerId]) | |
ALTER TABLE [dbo].[Customer] CHECK CONSTRAINT [FK_Customer_Customer_MergedToCustomerId] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Get-PSDrive -PSProvider FileSystem | Where-Object -Property Free | %{ write-host 'Checking drive ' $_.Root; set-location $_.Root; Get-ChildItem -File -Filter *.sln -Recurse; write-host 'Checked drive ' $_.Root; } > "C:\temp\mysterious solutions.txt" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To run: | |
# 1. Copy this script somewhere and amend the variables | |
# 2. Open Powershell command prompt | |
# 3. Run: set-executionpolicy unrestricted -scope process -force | |
# 4. "dot-source" this script, e.g. ./rename.ps1 | |
$old_namespace = "My.Old.Namespace" | |
$new_namespace = "My.New.Namespace" | |
$solution_folder = "C:\Users\Dan\Documents\GitHub\ExampleProject\src" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Web.Mvc; | |
using System.Web.WebPages; | |
namespace Whatever | |
{ | |
public static class HtmlHelperExtensions | |
{ | |
/// <summary> |