C# Script to Delete All Measures #377
Answered
by
otykier
Declan1984
asked this question in
🙋♀️TE3 Q&A
-
I'm trying to write a script that will delete all existing measures on a table. I'm relatively new to both C# and Tabular Editor so still trying to get a handle on how to leverage scripts to automate my modeling. Here is my code but it threw an error; can anyone share any insights on the best way to handle:
|
Beta Was this translation helpful? Give feedback.
Answered by
otykier
Jan 29, 2022
Replies: 1 comment 1 reply
-
In C#, you can't modify a collection while iterating it, so you have to copy the items into a new collection like so: var delete_measures = Model.Tables["Test Model"].Measures.ToList(); // .ToList() creates a copy of the collection
foreach(var measure in delete_measures) {
measure.Delete();
// No reason to look up the measure by name, since we already have a reference to it...
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Declan1984
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In C#, you can't modify a collection while iterating it, so you have to copy the items into a new collection like so: