class AllDefectsToSubscribers { static void Main() //根据项目把bug和通知订阅连接在一起 { var query = from defect in SampleData.AllDefects //query {System.Linq.Enumerable.JoinIterator<Chapter11.Model.Defect,Chapter11.Model.NotificationSubscription,Chapter11.Model.Project,<>f__AnonymousType2<string,string>>} join subscription in SampleData.AllSubscriptions //subscription {Chapter11.Model.NotificationSubscription} on defect.Project equals subscription.Project //看这句会不会执行下一句 select new 能执行就是会打印两条一样Summary不一样的Email //defect //{ 1: MP3 files crash system (2013/5/1-2013/5/23, Showstopper/Accepted, Tim Trotter -> Darren Dahlia)} //defect = { 2: Text is too big(2013/5/3-2013/5/9, Trivial/Closed, Deborah Denton -> n/a)} //{ 3: Sky is wrong shade of blue (2013/5/3-2013/5/19, Minor/Fixed, Colin Carton -> Tara Tutu)} //{ 4: Can't play files more than 200 bytes long (2013/5/4-2013/5/23, Major/Reopened, Darren Dahlia -> Darren Dahlia)} //{ 5: Installation is slow (2013/5/6-2013/5/15, Trivial/Fixed, Tim Trotter -> Tim Trotter)} //{ 6: DivX is choppy on Pentium 100 (2013/5/7-2013/5/29, Major/Accepted, Mary Malcop -> Darren Dahlia)} //{ 7: Client acts as virus (2013/5/8-2013/5/10, Showstopper/Closed, Deborah Denton -> n/a)} //{ 8: Subtitles only work in Welsh(2013/5/8-2013/5/23, Major/Fixed, Darren Dahlia -> Tim Trotter)} //{ 9: Voice recognition is confused by background noise (2013/5/9-2013/5/15, Minor/Closed, Colin Carton -> n/a)} //{10: User interface should be more caramelly (2013/5/9-2013/5/9, Trivial/Created, Tim Trotter -> Darren Dahlia)} //{11: Burning a CD makes the printer catch fire (2013/5/10-2013/5/29, Showstopper/Closed, Mary Malcop -> n/a)} //{12: Peer to peer pairing passes parameters poorly (2013/5/10-2013/5/12, Minor/Accepted, Tara Tutu -> Darren Dahlia)} //{13: Delay when sending message (2013/5/11-2013/5/20, Minor/Fixed, Darren Dahlia -> Tara Tutu)} //{14: Volume control needs to go to 11 (2013/5/11-2013/5/11, Minor/Created, Mary Malcop -> Darren Dahlia)} //{15: Splash screen fades too quickly (2013/5/11-2013/5/15, Minor/Fixed, Colin Carton -> Tara Tutu)} //{16: Text box doesn't keep up with fast typing (2013/5/12-2013/5/12, Major/Accepted, Deborah Denton -> Deborah Denton)} //{17: Password displayed in plain text (2013/5/12-2013/5/13, Showstopper/Closed, Darren Dahlia -> n/a)} //{18: Play button points the wrong way (2013/5/12-2013/5/17, Major/Fixed, Tim Trotter -> Tim Trotter)} //{19: Wizard needed for CD burning (2013/5/13-2013/5/20, Minor/Fixed, Colin Carton -> Colin Carton)} //{20: Subtitles don't display during fast forward (2013/5/13-2013/5/14, Trivial/Accepted, Mary Malcop -> Darren Dahlia)} //{21: Memory leak when watching Memento (2013/5/13-2013/5/13, Trivial/Created, Darren Dahlia -> Deborah Denton)} //{22: Profile screen shows login count of -1 (2013/5/13-2013/5/20, Major/Accepted, Deborah Denton -> Deborah Denton)} //{23: Server crashes under heavy load (3 users) (2013/5/13-2013/5/17, Major/Accepted, Tim Trotter -> Deborah Denton)} //{24: Unable to connect to any media server (2013/5/15-2013/5/18, Showstopper/Reopened, Tara Tutu -> Darren Dahlia)} //{25: UI turns black and white when playing old films (2013/5/15-2013/5/25, Minor/Fixed, Deborah Denton -> Tara Tutu)} //{26: Password reset changes passwords for all users (2013/5/16-2013/5/18, Showstopper/Closed, Mary Malcop -> n/a)} //{27: Modern music sounds rubbish (2013/5/17-2013/5/17, Trivial/Created, Tim Trotter -> Darren Dahlia)} //{28: Webcam makes me look bald (2013/5/18-2013/5/27, Showstopper/Fixed, Tim Trotter -> Tim Trotter)} //{29: Sound is distorted when speakers are underwater (2013/5/18-2013/5/18, Major/Created, Colin Carton -> Darren Dahlia)} //{30: Japanese characters don't display properly (2013/5/19-2013/5/23, Major/Accepted, Darren Dahlia -> Deborah Denton)} //{31: Video takes 100% of CPU (2013/5/20-2013/5/22, Major/Accepted, Tara Tutu -> Deborah Denton)} //{32: DVD Easter eggs unavailable (2013/5/22-2013/5/22, Trivial/Created, Tim Trotter -> Darren Dahlia)} //{33: Transparency is high for menus to be readable (2013/5/23-2013/5/25, Minor/Accepted, Mary Malcop -> Deborah Denton)} //{34: About box is missing version number (2013/5/24-2013/5/29, Minor/Fixed, Colin Carton -> Colin Carton)} //{35: Logs record confidential conversations (2013/5/25-2013/5/30, Major/Reopened, Tim Trotter -> Darren Dahlia)} //{36: Profanity filter is too aggressive (2013/5/27-2013/5/29, Minor/Fixed, Deborah Denton -> Tara Tutu)} //{37: Full screen mode fails on dual monitors (2013/5/27-2013/5/27, Minor/Created, Tara Tutu -> Deborah Denton)} //{38: Visualization hypnotises pets (2013/5/28-2013/5/29, Minor/Accepted, Colin Carton -> Deborah Denton)} //{39: Resizing while typing loses input (2013/5/29-2013/5/29, Trivial/Created, Mary Malcop -> Darren Dahlia)} //{40: Network is saturated when playing WAV file (2013/5/30-2013/5/31, Minor/Fixed, Tim Trotter -> Tim Trotter)} //{41: Media library tells user to keep the noise down (2013/5/31-2013/5/31, Major/Created, Tara Tutu -> Darren Dahlia)} select new { defect.Summary, subscription.EmailAddress }; foreach (var entry in query) //var entry { Summary = "MP3 files crash system", EmailAddress = "[email protected]" } //entry = { Summary = "MP3 files crash system", EmailAddress = "[email protected]" }, query = {System.Linq.Enumerable.JoinIterator<Chapter11.Model.Defect,Chapter11.Model.NotificationSubscription,Chapter11.Model.Project,<>f__AnonymousType2<string,string>>} // Summary = "Text is too big", EmailAddress = "[email protected]" } //{ Summary = "Text is too big", EmailAddress = "[email protected]" } //{ Summary = "Sky is wrong shade of blue", EmailAddress = "[email protected]" } //{ Summary = "Can't play files more than 200 bytes long", EmailAddress = "[email protected]" } //{ Summary = "Can't play files more than 200 bytes long", EmailAddress = "[email protected]" } //{ Summary = "Installation is slow", EmailAddress = "[email protected]" } //{ Summary = "Installation is slow", EmailAddress = "[email protected]" } //{ Summary = "DivX is choppy on Pentium 100", EmailAddress = "[email protected]" } //{ Summary = "DivX is choppy on Pentium 100", EmailAddress = "[email protected]" } //{ Summary = "Client acts as virus", EmailAddress = "[email protected]" } //{ Summary = "Subtitles only work in Welsh", EmailAddress = "[email protected]" } //{ Summary = "Subtitles only work in Welsh", EmailAddress = "[email protected]" } //{ Summary = "Voice recognition is confused by background noise", EmailAddress = "[email protected]" } //{ Summary = "User interface should be more caramelly", EmailAddress = "[email protected]" } //{ Summary = "Burning a CD makes the printer catch fire", EmailAddress = "[email protected]" } //{ Summary = "Burning a CD makes the printer catch fire", EmailAddress = "[email protected]" } //{ Summary = "Peer to peer pairing passes parameters poorly", EmailAddress = "[email protected]" } //{ Summary = "Delay when sending message", EmailAddress = "[email protected]" } //{ Summary = "Volume control needs to go to 11", EmailAddress = "[email protected]" } //{ Summary = "Volume control needs to go to 11", EmailAddress = "[email protected]" } //等等 { Console.WriteLine("{0}: {1}", entry.EmailAddress, entry.Summary); } } }
显示每个媒体播放器两次,一次显示 [email protected] 一次显示
[email protected],因为老板非常关心媒体播放器项目。
我们容易进行反转连接,调换左右序列的位置。结果包含的条目相同,只是顺序不同。在
LINQ to Objects的实现中,返回条目的顺序为:先返回使用左边序列中第1个元素的所有成对
数据能被返回(按右边序列的顺序),接着返回使用左边序列中的第2个元素的所有成对数据,
依次类推。右边序列被缓冲处理,不过左边序列仍然进行流处理---所以,如果你打算把一个巨大
序列连接到一个极小的序列上,应尽可能把小序列作为右边序列。这种操作仍然是延迟的:在
访问第1个数据对时,它才会开始执行,然后再从某个序列中读取数据。这时,会读取整个右边
序列,来建立一个从键到生成这些键的值的映射。之后,它就不需要再次读取右边的序列了,
这时你可能迭代左边的序列,生成适当的数据对。
输出
[email protected]: MP3 files crash system
[email protected]: MP3 files crash system
[email protected]: Text is too big
[email protected]: Text is too big
[email protected]: Sky is wrong shade of blue
[email protected]: Can't play files more than 200 bytes long
[email protected]: Can't play files more than 200 bytes long
[email protected]: Installation is slow
[email protected]: Installation is slow
[email protected]: DivX is choppy on Pentium 100
[email protected]: DivX is choppy on Pentium 100
[email protected]: Client acts as virus
[email protected]: Subtitles only work in Welsh
[email protected]: Subtitles only work in Welsh
[email protected]: Voice recognition is confused by background noise
[email protected]: User interface should be more caramelly
[email protected]: Burning a CD makes the printer catch fire
[email protected]: Burning a CD makes the printer catch fire
[email protected]: Peer to peer pairing passes parameters poorly
[email protected]: Delay when sending message
[email protected]: Volume control needs to go to 11
[email protected]: Volume control needs to go to 11
[email protected]: Splash screen fades too quickly
[email protected]: Splash screen fades too quickly
[email protected]: Text box doesn't keep up with fast typing
[email protected]: Password displayed in plain text
[email protected]: Play button points the wrong way
[email protected]: Play button points the wrong way
[email protected]: Wizard needed for CD burning
[email protected]: Wizard needed for CD burning
[email protected]: Subtitles don't display during fast forward
[email protected]: Subtitles don't display during fast forward
[email protected]: Memory leak when watching Memento
[email protected]: Memory leak when watching Memento
[email protected]: Profile screen shows login count of -1
[email protected]: Server crashes under heavy load (3 users)
[email protected]: Unable to connect to any media server
[email protected]: Unable to connect to any media server
[email protected]: UI turns black and white when playing old films
[email protected]: UI turns black and white when playing old films
[email protected]: Password reset changes passwords for all users
[email protected]: Modern music sounds rubbish
[email protected]: Modern music sounds rubbish
[email protected]: Webcam makes me look bald
[email protected]: Sound is distorted when speakers are underwater
[email protected]: Japanese characters don't display properly
[email protected]: Video takes 100% of CPU
[email protected]: Video takes 100% of CPU
[email protected]: DVD Easter eggs unavailable
[email protected]: DVD Easter eggs unavailable
[email protected]: Transparency is high for menus to be readable
[email protected]: About box is missing version number
[email protected]: About box is missing version number
[email protected]: Logs record confidential conversations
[email protected]: Profanity filter is too aggressive
[email protected]: Full screen mode fails on dual monitors
[email protected]: Full screen mode fails on dual monitors
[email protected]: Visualization hypnotises pets
[email protected]: Visualization hypnotises pets
[email protected]: Resizing while typing loses input
[email protected]: Network is saturated when playing WAV file
[email protected]: Network is saturated when playing WAV file
[email protected]: Media library tells user to keep the noise down
[email protected]: Media library tells user to keep the noise down