Skip to content

Instantly share code, notes, and snippets.

@danielwertheim
danielwertheim / 01-upsert.cs
Created April 14, 2012 09:10
Named queries
using (var session = database.BeginSession())
{
session.Advanced.UpsertNamedQuery<Customer>("CustomersViaSP", qb => qb.Where(c =>
c.CustomerNo >= default(int)
&& c.CustomerNo <= default(int)
&& c.DeliveryAddress.Street == string.Empty));
}
@danielwertheim
danielwertheim / JsonApprovals.cs
Created May 10, 2012 19:51
Some approvals fiddling
public static class JsonApprovals
{
public static void VerifyAsJson<T>(T item)
{
VerifyJson(item.ToJson()); //Using extension method ToJson from ServiceStack.Text
}
public static void VerifyJson(string json)
{
Approvals.Verify(new ApprovalTextWriter(json.Dump(), "txt")); //Using extension method Dump from ServiceStack.Text
@danielwertheim
danielwertheim / 01_Test.cs
Created May 11, 2012 07:52
ExpressionComparer does not support AnonymousTypes
private static LambdaExpression ExpressionFactory(int customerNoFrom, int customerNoTo)
{
Func<Expression<Func<Customer, bool>>, LambdaExpression> fn = expression => expression;
return fn(c =>
c.CustomerNo >= customerNoFrom && c.CustomerNo <= customerNoTo &&
c.DeliveryAddress.Street == "The delivery street #544");
}
static void Main(string[] args)
@danielwertheim
danielwertheim / gist:2950174
Created June 18, 2012 19:18
StartNewProjectValidator
public class StartNewProjectValidator : ICommandValidator<StartNewProject>
{
protected readonly ISisoDatabase Readstore;
public StartNewProjectValidator(ISisoDatabase readstore)
{
Readstore = readstore;
}
public virtual ViolationsContainer Validate(StartNewProject cmd)
@danielwertheim
danielwertheim / 01-Inheritance.cs
Created July 19, 2012 22:05
SisoDb - Inheritance
class Program
{
static void Main(string[] args)
{
var db = "data source=.;initial catalog=fff;integrated security=true;".CreateSql2012Db();
db.CreateIfNotExists();
var p = new Foo2 { Name = "Adam", Points = 1 };
db.UseOnceTo().Insert<Foo>(p);
}
@danielwertheim
danielwertheim / gist:3149566
Created July 20, 2012 08:21
Rough key-value store
class Program
{
static void Main(string[] args)
{
var db = "data source=.;initial catalog=fff;integrated security=true;".CreateSql2012Db();
db.EnsureNewDatabase();
var mdoc = new Doc { Name = "MD doc" };
mdoc.Set("Substitute", "Ibuprofen");
@danielwertheim
danielwertheim / formatter.cs
Created September 8, 2012 17:38
WebAPI ServiceStack
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Formatting;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using EnsureThat;
using iLogMyDay.Core.Serialization;
@danielwertheim
danielwertheim / gist:4049191
Created November 10, 2012 00:20
Search dep on NuGet
http://packages.nuget.org/v1/FeedService.svc/Packages?$filter=substringof('SisoDb',%20Dependencies)%20eq%20true&$select=Id,Dependencies
@danielwertheim
danielwertheim / ReallyDoDropCreateDatabaseIfModelChanges.cs
Created November 29, 2012 09:54
ReallyDoDropCreateDatabaseIfModelChanges
public class ReallyDoDropCreateDatabaseIfModelChanges<TContext> : IDatabaseInitializer<TContext> where TContext : DbContext
{
protected const string Sql =
"if (select DB_ID('{0}')) is not null\r\n"
+ "begin\r\n"
+ "alter database [{0}] set offline with rollback immediate;\r\n"
+ "alter database [{0}] set online;\r\n"
+ "drop database [{0}];\r\n"
+ "end";
@danielwertheim
danielwertheim / gist:5378155
Created April 13, 2013 12:14
Early draft of my CouchDb client
using System;
using System.Collections.Generic;
using MyCouch;
namespace CouchDb
{
public class Program
{
static void Main(string[] args)
{