Skip to content

Instantly share code, notes, and snippets.

@taylonr
taylonr / DataProfiler.cs
Created December 15, 2011 14:09
Profiler Interface
public class DataProfiler : IProfiler
{
public DataProfiler()
{
Enabled = true;
}
public bool Enabled { get; set; }
public void Update(PetaPocoSqlInfo info)
@taylonr
taylonr / DataProfiler.cs
Created December 15, 2011 15:33
DataProfiler Implementation
public class DataProfiler : ISqlProfiler
{
public DataProfiler()
{
Enabled = true;
}
public bool Enabled { get; set; }
public void Update(PetaPocoSqlInfo info)
@taylonr
taylonr / PetaPocoGlimpse.cs
Created December 15, 2011 15:34
PetaPocoGlimpse
[GlimpsePlugin]
public class PetaPocoGlimpsePlugin : IGlimpsePlugin
{
public object GetData(HttpContextBase context)
{
if (context.Items[DataProfiler.PetaKey] == null)
return new List<object[]> { new[] { "Log" }, new[] { "No database requests or database logging not switched on (Compilation debug='true' or ForceLogging='true' on
PetaPoco.DatabaseWithLogging)", "warn" } };
var sqls = new List<object[]> {new[] {"#", "Time(ms)", "Sql", "Parameters"}};
@taylonr
taylonr / SqlInfo.cs
Created December 17, 2011 14:39
SqlInfo
public class SqlInfo
{
public double Time { get; set; }
public string FormattedSql { get; set; }
public string Sql { get; set; }
public IDataParameterCollection Parameters { get; set; }
}
@taylonr
taylonr / ISqlProfiler.cs
Created December 17, 2011 14:40
ISqlProfiler
public interface ISqlProfiler
{
bool Enabled { get;}
void Update(PetaPocoSqlInfo info);
}
@taylonr
taylonr / Purchase.sql
Created December 21, 2011 19:29
Collation
CREATE TYPE [dbo].[MyRecords] AS TABLE(
[Id] [int] NOT NULL,
[ModuleId] [int] NOT NULL,
[Code] [nvarchar](20) COLLATE SQL_Latin1_General_CP1_CS_AS NOT NULL,
PRIMARY KEY CLUSTERED
(
[Id] ASC,
[ModuleId] ASC,
[Code] ASC
)WITH (IGNORE_DUP_KEY = OFF)
@taylonr
taylonr / executescalar
Created February 20, 2012 17:27
Petapoco ExecuteScalar
var returnCode = Database.ExecuteScalar<int>(
"exec GetData @userId, @date",
new {userId = userId, @date = DateTime.Now});
@taylonr
taylonr / ReturnVal
Created February 20, 2012 17:30
PetaPoco Stored Procedure Return Value
var sql = new Sql().Append("declare @@result int")
.Append("exec GetData @userId, @date",
new {userId = userId, @date = DateTime.Now})
.Append("select @@result);
var ret = Database.ExecuteScalar<int>(sql);
@taylonr
taylonr / TestingOpenrasta
Created April 7, 2012 02:19
Integration test for OpenRasta
[Test]
public void Should_Add_User()
{
var user = new UserInput {Email = "autotest@example.com", FirstName = "automated", LastName = "user", Password = "abc"};
using (var host = new InMemoryHost(new Configuration()))
{
var req = new InMemoryRequest
{
Uri = new Uri("http://localhost/users"),
@taylonr
taylonr / gist:2779125
Created May 24, 2012 02:40 — forked from beolson/gist:2778777
Playing around with validation
// make sure to add autofac to the project
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autofac;
using Autofac.Configuration;
namespace ValidationTest