Skip to content

Instantly share code, notes, and snippets.

@jeremiahredekop
Last active November 19, 2015 18:20
Show Gist options
  • Save jeremiahredekop/f57fc89396019215dac7 to your computer and use it in GitHub Desktop.
Save jeremiahredekop/f57fc89396019215dac7 to your computer and use it in GitHub Desktop.
sample sql denormalizer using paramol & projac
using Paramol.SqlClient;
using Projac;
namespace Sample
{
public static class PortfolioProjectionUsingBuilder
{
public static readonly AnonymousSqlProjection Instance = new AnonymousSqlProjectionBuilder().
When<PortfolioAdded>(@event =>
TSql.NonQueryStatement(
"INSERT INTO [Portfolio] (Id, Name) VALUES (@P1, @P2)",
new { P1 = TSql.Int(@event.Id), P2 = TSql.NVarChar(@event.Name, 40) }
)).
When<PortfolioRemoved>(@event =>
TSql.NonQueryStatement(
"DELETE FROM [Portfolio] WHERE Id = @P1",
new { P1 = TSql.Int(@event.Id) }
)).
When<PortfolioRenamed>(@event =>
TSql.NonQueryStatement(
"UPDATE [Portfolio] SET Name = @P2 WHERE Id = @P1",
new { P1 = TSql.Int(@event.Id), P2 = TSql.NVarChar(@event.Name, 40) }
)).
Build();
}
}
@jeremiahredekop
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment