Is there a way to get all the combinations possibles in an ObservableCollection?
I have a model like this:
public string MyProperty { get; set; }
public string MyProperty2 { get; set; }
public string MyProperty3 { get; set; }
public string MyProperty4 { get; set; }
public string MyProperty5 { get; set; }
public string MyProperty6 { get; set; }
public string MyProperty7 { get; set; }
public string MyProperty8 { get; set; }
And I fill this model with data from a spreadsheet, but some values have zero or empty values (which I need to exclude). Is there a way to get all the possible combinations with the same pattern?
For example, all the combinations with values different from 0 in all the properties, and all the combinations when there has only one property with value and the others zero, etc.
So far I have something like this:
var group1 = _sourceStructure.Where(c => c.MyProperty != "0" && c.MyProperty2 != "0" && c.MyProperty3 != "0" && c.MyProperty4 != "0"
&& c.MyProperty5 != "0" && c.MyProperty6 != "0" && c.MyProperty7 != "0" && c.MyProperty8 != "0");
But with this I need to use more than 30 cases to evaluate, is there a way to get all the possible combinations using LINQ or another solution?
I want to build an SQL query with the values from the collection, but if the value has 0 or is empty, I'll not add that value to the query. I want to get all the combinations with the same pattern in order to be able to put all of the items with same pattern within an IN in SQL.
The output data will be something like this:
string query = @"Select field1, field2, field3, fieldn FROM table WHERE "
query = query + "field1 = " + _sourceStructure.MyProperty1;
query = query + "fieldN = " + _sourceStructure.MyPropertyN;
Basically, I don't care which the value is. I only need to group the collection with all the possible combinations with the same pattern.
Sample data from the original file in Excel:
MyProperty1 MyPropert2 MyPropertN
Row1 0 1 3
Row2 2 0 6
Row3 0 5 9
Row4 9 9 4
Row5 4 3 6
Row6 0 0 0
Here, for example, I'm expecting that Row1 and Row3 will be in the same group (the values are not the same but the "structure" it's the same), and then Row4 and Row5 will be another group, Row6 another one, and Row2 another one.