Skip to content

Instantly share code, notes, and snippets.

@jeremiahredekop
Last active November 19, 2015 18:20
Show Gist options
  • Select an option

  • Save jeremiahredekop/f57fc89396019215dac7 to your computer and use it in GitHub Desktop.

Select an option

Save jeremiahredekop/f57fc89396019215dac7 to your computer and use it in GitHub Desktop.

Revisions

  1. jeremiahredekop revised this gist Nov 19, 2015. 1 changed file with 24 additions and 18 deletions.
    42 changes: 24 additions & 18 deletions handler.cs
    Original file line number Diff line number Diff line change
    @@ -1,20 +1,26 @@
    public static class PortfolioProjectionUsingBuilder
    using Paramol.SqlClient;
    using Projac;

    namespace Sample
    {
    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();
    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();
    }
    }
  2. jeremiahredekop created this gist Nov 19, 2015.
    20 changes: 20 additions & 0 deletions handler.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    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();
    }