Please do help me out in one of the scenario, where I got stucked.
It goes like this.
A dynamically created List of table and List of Fields( inside Table ) using PropertyGrid.
BindingList<Table> table = new BindingList<Table>(); [Serializable] [TypeConverter(typeof(TableConverter))] public class Table { private string _name = string.Empty; private HeaderCollection _hc = new HeaderCollection(); private BindingList<Fields> _fc = new BindingList<Fields>(); public Guid key; public Table() { key = Guid.NewGuid(); } [DisplayName( "Table Fields" ), Editor( typeof( FieldCollectionEditor ), typeof( UITypeEditor ) )] public BindingList<Fields> Fields { get { return _fc; } set { _fc = value; } } [DisplayName( "Table Header" )] public HeaderCollection Headers { get { return _hc; } set { _hc = value; } } [DisplayName( "Table Name" )] public string Name { get { return _name; } set { _name = value; } } }
Field class definition
[Serializable] public class Fields { private string _name = string.Empty; public Guid Key; private List<string> _value = new List<string>(); [Browsable( false )] public List<string> Value { get { return _value; } set { _value = value; } } public Fields() { Key = Guid.NewGuid(); } [DisplayName( "Field Name" )] public string Name { get { return _name; } set { _name = value; } } [DisplayName( "Map" )] public bool Map { get; set; } }
Field class contain List of string to hold one or more value.
My Problem is : Need to cross join all values beloging to all fields from a table and display the data in tabular format. I have used this query, but this does not work as it fetch out the values one by one, instead i need a coross join of all values from all fields at one go.
var result = table.SelectMany(
tbl => tbl.Fields.SelectMany(
f => f.Value.Select(v => new { i = v })));
For Example, Lets say :
F1 has Value11
F2 has Value21
F3 has Value31 and Value 32
F4 has Value41, Value42 and Value43
The result should be in this format for each table and all fields’ value.
Value11 Value21 Value 31 Value 41
Value11 Value21 Value 31 Value 42
Value11 Value21 Value 31 Value 43
Value11 Value21 Value 32 Value 41
Value11 Value21 Value 32 Value 42
Value11 Value21 Value 32 Value 43
Let me elaborate this a little bit more. For example if we have
List<string> master = new List<string>();
List<string> child = new List<string>();
List<string> child1 = new List<string>();
List<string> child2 = new List<string>();
and a Linq query to fetch out
var q = from m in master
from c1 in child1
from c in child
from c2 in child2
select new { m, c, c1, c2 };
I exactly need to write the above query like this to fetch out field values but the problem is fields are generated dynamically and so the values inside it, hence i need some sort of recussive method or linq procedure to yeild the result as provided in sample above.