c# - Fill grid's datasource with distinct combinations of data -



i have 1 problem filling grid.
okey,
imagine have grid prints data basketball team.
we have 4 main classes:

public class player {     public string playername { get; set; } }  public class staff {     public string staffname { get; set; } }  public class fan {     public string fanname { get; set; }     public list<string> fanfavoriteteam { get; set; } }  public class team {     public string teamname { get; set; }     public list<player> players { get; set; }     public list<staff> staff { get; set; }     public list<fan> fans { get; set; } } 

... , of course class fills grid

public class result {     public string teamname { get; set; }     public string playername { get; set; }     public string staffname { get; set; }     public string fanname { get; set; }     public string fanfavoriteteam { get; set; } } 

i want print possible combinations,for example assume have data:
team name - golden state warriors
players - stephen curry, kevin durant
staff - steve kerr, alvin gentry, ron adams
fans - duke allard(favorite: celtics,lakers), dorian macy, lamont collingwood

grid should print info:

1st row)golden state - stephen curry - steve kerr - duke allard - celtics 2)golden state - stephen curry - steve kerr - duke allard - lakers 3)golden state - stephen curry - steve kerr - dorian macy 4)golden state - stephen curry - steve kerr - lamont collingwood 5)golden state - stephen curry - alvin gentry - duke allard - celtics 6)golden state - stephen curry - alvin gentry - duke allard - lakers 7)golden state - stephen curry - alvin gentry - dorian macy 8)golden state - stephen curry - alvin gentry - lamont collingwood 9)golden state - stephen curry - ron adams - duke allard - celtics 10)golden state - stephen curry - ron adams - duke allard - lakers 11)golden state - stephen curry - ron adams - dorian macy 12)golden state - stephen curry - ron adams - lamont collingwood 13)golden state - kevin durant - steve kerr - duke allard - celtics 14)golden state - kevin durant - steve kerr - duke allard - lakers 15)golden state - kevin durant - steve kerr - dorian macy 16)golden state - kevin durant - steve kerr - lamont collingwood 17)golden state - kevin durant - alvin gentry - duke allard - celtics 18)golden state - kevin durant - alvin gentry - duke allard - lakers 19)golden state - kevin durant - alvin gentry - dorian macy 20)golden state - kevin durant - alvin gentry - lamont collingwood 21)golden state - kevin durant - ron adams - duke allard - celtics 22)golden state - kevin durant - ron adams - duke allard - lakers 23)golden state - kevin durant - ron adams - dorian macy 24)golden state - kevin durant - ron adams - lamont collingwood 

p.s. want achieve without chained foreach statements
p.p.s. sorry long description

you can use linq looping you:

var result = t in teams              p in players              s in staff              f in fans              select new result {                teamname = t.teamname,                playername = p.playername,                staffname = s.staffname,                fanname = f.fanname,              } 

this cross-join of tables, no restrictions, every team matched every player, staff, , fan, , we're getting cartesian product of data.


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -