Skip to content

Instantly share code, notes, and snippets.

@litera
litera / NPoco strong typed Stored Procedures calls T4.md
Last active June 27, 2023 11:37
NPoco/PetaPoco strong typed and named stored procedures T4 generator

NPoco/PetaPoco stored procedures with named strong type parameters

StoredProcedures.tt file automatically generates a C# code file with calsses and methods corresponding to your database stored procedure definitions. This is then used to simply call stored procedures within NPoco/PetaPoco and avoid magic strings and parameter type guessing. It also supports output parameters.

Stored procedures naming conventions

In order to have your stored procedure calls well structured there are particular yet simple naming conventions you should follow when creating your stored procedures:

  1. Name your stored procedures as ClassName_Method
  2. If a particular stored procedure shouldn't be parsed you should omit underscore character in its name; this will make it private from the perspective of your C# as it will only be accessible to other stored procedures but won't be parsed.
@fushnisoft
fushnisoft / clariondate.sql
Last active January 5, 2024 14:33
Convert a Clarion Date (INT) to SQL DateTime
DECLARE @ClarionDate INT = 47563
DECLARE @SqlDateTime DATETIME
-- Convert the clarion DATE into and SQL DateTime
SET @SqlDateTime = DateAdd(day, @ClarionDate - 4, '1801-01-01')
SELECT @SqlDateTime AS 'SQL Date Time'
-- Now convert it back from and SQL DateTime to a Clarion Date
SET @ClarionDate = DateDiff(day, DateAdd(day, -4, '1801-01-01'), @SqlDateTime)