Skip to content

Instantly share code, notes, and snippets.

@yreynhout
Last active August 29, 2015 13:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yreynhout/10687251 to your computer and use it in GitHub Desktop.
Save yreynhout/10687251 to your computer and use it in GitHub Desktop.
Declarative Projac Projection - Teaser
public static class DeclarativeTSqlProjection
{
public static void Sample()
{
var specification =
TSql.Projection().
When<StartedShopping>(@event =>
TSql.NonQuery(
"INSERT INTO [Cart] ([CartId], [Started], [Ended]) VALUES (@CartId, @Started, NULL)",
new
{
CartId = TSql.Int(@event.CartId),
Started = TSql.DateTimeOffset(@event.When)
})
).
When<CheckedoutCart>(@event =>
TSql.Compose(
@event.Items.Select(item => TSql.NonQuery(
"INSERT INTO [CartContent] ([CartId], [ItemId], [Count]) VALUES (@CartId, @ItemId, @Count)",
new
{
CartId = TSql.Int(@event.CartId),
ItemId = TSql.Int(item.Id),
Count = TSql.Int(item.Count)
}))).
Compose(
TSql.NonQuery(
"UPDATE [Cart] SET [Ended] = @Ended WHERE [CartId] = @CartId",
new
{
CartId = TSql.Int(@event.CartId),
Ended = TSql.DateTimeOffset(@event.When)
}))
).
Build();
//now execute that spec
}
}
@cduhard
Copy link

cduhard commented Apr 15, 2014

I like this.

@yreynhout
Copy link
Author

@cduhard It's here, in 0.0.20 :-)

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