Last active
August 29, 2015 13:59
-
-
Save yreynhout/10687251 to your computer and use it in GitHub Desktop.
Declarative Projac Projection - Teaser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I like this.