Well, as the title says. I’d like to use a script component destination, and then utilize LINQ to select which rows to process for output.
For a bit more background, I have this ugly merged thing with a one-to-many relationship. The rows look sort of like:
[ID] [Title] [OneToManyDataID]
1 Item one 2
1 Item one 4
1 Item one 3
3 Item two 1
3 Item two 5
We’ll call the objects [Item], which has the ID and Title columns and [OneToMany]
I was hoping I could throw the entire thing to a script component destination, and then use LINQ to do something like group by the item and only take the data from the highest OneToMany object. Sort of like:
foreach(var item in Data.GroupBy(d=>d.Item).Select(d=> new {Item = d.Key})){
//Then pick out the highest OneToMany ID for that row to use with it.
}
I realize there are probably better LINQ queries to accomplish this, but the point is, the script component in SSIS seems to only allow working with it on a per-row basis, with the predefined ProcessInputRow-method. Where I’d like to determine exactly which rows are processed and what properties are passed to that method.
How would I go about doing this?
To restate your problem, how can I make an Script Transformation stop processing row-by-row? By default, a script transformation is going to be a synchronous component – 1 row in, 1 row out. You’ll want to change that to an asynchronous component 1 row in – 0 to many rows out.
On your Script Transformation Editor, the Inputs and Outputs tab, for your output collection
Output 0change the value of SynchronousInputID from whatever it is toNone.Don’t cast stones on my LINQ code-I trust you can handle making that work right. The intention of this code block is to demonstrate how you would collect your rows for processing and then pass them on to a downstream consumer after modifying them. I commented on the methods to help you understand what each one of them does in the script component life cycle but if you’d rather read MSDN they know a bit more than I do 😉
Configuration of the Script Transformation