Helo everyone,
I have this method written in C#, and it basically search for a register on the database, and if it's repeatable (isRepeatable = true), it will increment and insert itself again in a list with a different date, but with the same Id and Name properties. I do specify too the repeating type (daily, weekly, monthly or yearly), and it will go until it reaches the value specified in the RepeatingEndDate or the date that i specify on the method, so it won't loop infinitely through repeatable registers that don't have a RepeatingEndDate specified.
In summary, if i have a register like this in my Database:
Id: 1
Name: Foo
Date: 03/10/2014
IsRepeatable: true
RepetitionType: 3 (Monthly)
RepeatingEndDate 05/10/2014
This will be the list of registers that my C#'s method will output from that single register:
Id: 1
Name: Foo
Date: 03/10/2014
IsRepeatable: true
RepetitionType: 3 (Monthly)
RepeatingEndDate 05/10/2014
Id: 1
Name: Foo
Date: 04/10/2014
IsRepeatable: true
RepetitionType: 3 (Monthly)
RepeatingEndDate 05/10/2014
Id: 1
Name: Foo
Date: 05/10/2014
IsRepeatable: true
RepetitionType: 3 (Monthly)
RepeatingEndDate 05/10/2014
Note that all the properties except the Date are the same, because i'm creating new Objects with all the same properties, but taking in consideration the repetition that i want and setting only the date. My goal here is to process repeatable data without saving multiple data and, in my actual case, letting the application handle the repetition.
But i found this is really CPU intense at some point, and i had the idea of converting this all to Stored Procedure in SQL SERVER.
My question is: Is it possible to convert all this C# logic into SQL SERVER stored procedure and just consume this proc in my application as a List of Registers? If so, my result will basically be getting a list of registers, some may have the same Id, Name, Etc, but different dates, according to it's repetition.
EDIT
Plain code is here: https://codereview.stackexchange.com/questions/83777/refactoring-a-loop-through-repetitive-registers