Skip to content

Instantly share code, notes, and snippets.

View pdwetz's full-sized avatar

Peter Wetzel pdwetz

View GitHub Profile
@pdwetz
pdwetz / T-SQL-POCO.sql
Last active April 28, 2021 17:30
Generates a POCO (plain old C# object) based on the table/view schema in SQL Server. Assumes you're already in the correct database and don't need a special schema. Based on the mysql gist (https://gist.github.com/pdwetz/5368441) and MS docs (https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/sql-server-data-type-mappings)
declare @table varchar(50);
set @table = 'TableOrViewName';
select 'public ' + tps.dest
+ (case when IS_NULLABLE = 'YES' and tps.dest != 'string' then '? ' else ' ' end)
+ column_name + ' { get; set; }'
from information_schema.columns c
join (
select 'char' as origin, 'string' as dest union all
select 'varchar', 'string' union all
@pdwetz
pdwetz / web.config
Created August 29, 2016 20:29
Nancy v2 with Razor - .net 4.6.1
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="dotless" type="dotless.Core.configuration.DotlessConfigurationSectionHandler, dotless.Core" />
</configSections>
<appSettings>
</appSettings>
<connectionStrings>
</connectionStrings>
<system.web>
@pdwetz
pdwetz / nancyfx2-error.txt
Created April 20, 2016 18:31
Null error in NancyFx v2 with Spark view engine and new async NancyModule
Error Details
Nancy.RequestExecutionException: Oh noes! ---> System.NullReferenceException: Object reference not set to an instance of an object.
at Views_home.Viewfb8e7c8d7e1547039246bf7c625fe9df.RenderViewLevel1()
at Views_home.Viewfb8e7c8d7e1547039246bf7c625fe9df.Render()
at Spark.SparkViewBase.RenderView(TextWriter writer)
at Nancy.ViewEngines.Spark.NancySparkView.Execute()
at Nancy.ViewEngines.Spark.SparkViewEngine.<>c__DisplayClass8.b__7(Stream stream)
at Nancy.Responses.MaterialisingResponse.PreExecute(NancyContext context)
at Nancy.NancyEngine.d__9.MoveNext()
@pdwetz
pdwetz / EventsModule.cs
Created August 15, 2014 01:39
Nancy Binding Issue
namespace Nancy.Demo.ModelBinding
{
using System.Linq;
using Database;
using Models;
using Nancy.ModelBinding;
public class EventsModule : NancyModule
{
public EventsModule()
@pdwetz
pdwetz / gist:5368441
Last active August 15, 2021 10:12
Outputs a POCO for a given MySql table. Based on http://stackoverflow.com/a/13918084/21865 with mild formatting changes and additional types added.
select 'replacewithtablename' into @table;
select 'replacewithdatabasename' into @schema;
select concat('public class ',@table,'{')
union
select concat('public ',tps.dest,' ',column_name,'{get;set;}')
from information_schema.columns c
join (
select 'char' as orign ,'string' as dest union all
@pdwetz
pdwetz / gist:5193287
Created March 19, 2013 02:34
UrlFor() doesn't seem to be encoding forward slashes ("/") properly. The result of the following is "/alpha/1/abc/def%26ghi%3Djkl", but should have the forward slash encoded.
public class AlphaController
{
private readonly UrlRegistry _urlregistry;
public AlphaController(UrlRegistry urlreg)
{
_urlregistry = urlreg;
}
public string Get_Alpha_Id_Name(AlphaInputModel input)
@pdwetz
pdwetz / gist:4677630
Last active December 22, 2016 16:53
Useful little bits for FubuMVC; rather than dig through source, keeping them here for quick reference. I'll eventually post an article with them that's better for public consumption.
// If using FubuAthentication, update auth ticket as needed (e.g. account creation or key updated)
private readonly IAuthenticationSession _auth;
public SomeController(IAuthenticationSession auth) { _auth = auth; }
_auth.MarkAuthenticated(user.Email);
// If using FubuAuthentication, make route available to anonymous users
[NotAuthenticated]
public FubuContinuation SomeRoute(SomeRouteInputModel input)
{
// Use a continuation to redirect to input-less page
@pdwetz
pdwetz / gist:4675198
Created January 30, 2013 17:59
JsonBindingConvention for FubuMVC; tells it to use Json.Net for parsing input models for the JsonInput attribute.
using System;
using System.Collections.Generic;
using System.Linq;
using FubuMVC.Core.Registration;
using FubuMVC.Core.Registration.Nodes;
using FubuMVC.Core.Resources.Conneg;
using FubuMVC.Core.Runtime.Formatters;
using FubuMVC.Json;
public class JsonBindingConvention : IConfigurationAction
@pdwetz
pdwetz / gist:4629697
Created January 24, 2013 23:39
Custom Simple Data pluralizer; makes an attempt to properly handle words ending in "y".
using System;
using Simple.Data;
/// <summary>
/// Custom Simple Data pluralizer; makes an attempt to properly handle words ending in "y".
/// </summary>
public class Pluralizer : IPluralizer
{
public bool IsSingular(string word) { return !IsPlural(word); }