Skip to content

Instantly share code, notes, and snippets.

@davidbreyer
davidbreyer / GenericRepository.cs
Last active November 8, 2022 00:53
Generic Repository Pattern for Entity Framework
//Generic Repository Pattern for Entity Framework
//http://www.tugberkugurlu.com/archive/generic-repository-pattern-entity-framework-asp-net-mvc-and-unit-testing-triangle
public abstract class GenericRepository<C, T> :
IDisposable, IGenericRepository<T> where T : class where C : DbContext, new() {
private C _entities = new C();
public C Context {
get { return _entities; }
set { _entities = value; }
@davidbreyer
davidbreyer / DropSqlTables.sql
Last active December 15, 2017 15:52
T-SQL script that will drop each table in the database. Requires repeated executions.
EXEC sp_MSforeachtable @command1 = "DROP TABLE ?"
--Or maybe just delete
EXEC sp_MSForEachTable "DELETE FROM ?"
--or truncate
EXEC sp_MSForEachTable "TRUNCATE TABLE ?"
@davidbreyer
davidbreyer / ScriptCodeFirstDatabase.txt
Created March 14, 2014 15:01
Script a Code First database from the initial migration
//Must execute in the Package Manager Console
Update-Database -Script -SourceMigration: 0
@davidbreyer
davidbreyer / connect to drive.ps1
Created March 17, 2014 13:19
Powershell script to connect to a remote drive
net use X: \\<servername>\F$ /Persistent:No /user:<domain>\<username> <password>
@davidbreyer
davidbreyer / AppHost.cs
Last active August 29, 2015 13:57
Use Microsoft Unity Dependency Injection with ServiceStack
//Update the Configure method of the AppHost to resemble the following.
public sealed class AppHost : AppHostBase
{
public AppHost()
: base("ServiceStack", typeof(ExampleService).Assembly)
{
}
public override void Configure(Container container)
{
@davidbreyer
davidbreyer / UnityConfig.cs
Created March 21, 2014 13:13
How to get Unity.Mvc5 and Unity.WebApi working together in a project
using Microsoft.Practices.Unity;
using System.Web.Http;
using System.Web.Mvc;
namespace WebApplication1
{
public static class UnityConfig
{
public static void RegisterComponents()
{
@davidbreyer
davidbreyer / Get unique items from a list using Linq.cs
Created March 25, 2014 14:03
Select distinct items from a List using LINQ
var distinctMessages = messages.GroupBy(x => x.Text).Select(group => group.First()).ToList();
@davidbreyer
davidbreyer / main.swift
Last active October 17, 2022 20:48
Get local date and time in Swift
//
// main.swift
// ConsoleApp1
//
import Foundation
let date = NSDate();
let dateFormatter = NSDateFormatter()
dateFormatter.timeStyle = NSDateFormatterStyle.MediumStyle //Set time style
@davidbreyer
davidbreyer / main.swift
Created June 11, 2014 15:58
Create and Update Generic List in Apple Swift
//
// main.swift
// ConsoleApp1
import Foundation
var cityList = Array<String>()
cityList.append("Vienna")
cityList.append("Munich")
cityList.append("Berlin")
using EntityFramework.Auditing;
using SESPolicy.Api.Web.Components;
using SESPolicy.Common;
using SESPolicy.Model;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Net.Http;