SelectMany - Compound from 2

Query
public void Linq15()
{
List customers = GetCustomerList();

var orders =
from c in customers
from o in c.Orders
where o.Total < 500.00M
select new { c.CustomerID, o.OrderID, o.Total };

ObjectDumper.Write(orders);
}
Lambda Expression
public void DataSetLinq15()
{
var customers = testDS.Tables["Customers"].AsEnumerable();
var orders = testDS.Tables["Orders"].AsEnumerable();

var smallOrders =
customers.SelectMany(c => orders, (c, o) => new {c, o})
.Where(@t => @t.c.Field("CustomerID") == @t.o.Field("CustomerID") && @t.o.Field("Total") < 500.00M)
.Select(@t => new {
CustomerID = @t.c.Field("CustomerID"),
OrderID = @t.o.Field("OrderID"),
Total = @t.o.Field("Total")
});
ObjectDumper.Write(smallOrders);
}
Output
CustomerID=ALFKI OrderID=10702 Total=330.00
CustomerID=ALFKI OrderID=10952 Total=471.20
CustomerID=ANATR OrderID=10308 Total=88.80
CustomerID=ANATR OrderID=10625 Total=479.75
CustomerID=ANATR OrderID=10759 Total=320.00
CustomerID=ANTON OrderID=10365 Total=403.20
CustomerID=ANTON OrderID=10682 Total=375.50
CustomerID=AROUT OrderID=10355 Total=480.00
CustomerID=AROUT OrderID=10453 Total=407.70
CustomerID=AROUT OrderID=10741 Total=228.00
CustomerID=AROUT OrderID=10743 Total=319.20
CustomerID=AROUT OrderID=10793 Total=191.10
CustomerID=AROUT OrderID=10864 Total=282.00
CustomerID=AROUT OrderID=10920 Total=390.00
CustomerID=AROUT OrderID=11016 Total=491.50
CustomerID=BERGS OrderID=10445 Total=174.90
CustomerID=BERGS OrderID=10689 Total=472.50
CustomerID=BERGS OrderID=10778 Total=96.50
CustomerID=BLAUS OrderID=10501 Total=149.00
CustomerID=BLAUS OrderID=10509 Total=136.80
CustomerID=BLAUS OrderID=10582 Total=330.00
CustomerID=BLAUS OrderID=10614 Total=464.00
CustomerID=BLONP OrderID=10628 Total=450.00
CustomerID=BOLID OrderID=10970 Total=224.00
CustomerID=BONAP OrderID=10331 Total=88.50
CustomerID=BONAP OrderID=10730 Total=484.26
CustomerID=BONAP OrderID=10732 Total=360.00
CustomerID=BONAP OrderID=10940 Total=360.00
CustomerID=BSBEV OrderID=10289 Total=479.40
CustomerID=BSBEV OrderID=10484 Total=386.20
CustomerID=BSBEV OrderID=10538 Total=139.80
CustomerID=BSBEV OrderID=10539 Total=355.50
CustomerID=BSBEV OrderID=10578 Total=477.00
CustomerID=BSBEV OrderID=10599 Total=493.00
CustomerID=BSBEV OrderID=10947 Total=220.00
CustomerID=CACTU OrderID=10521 Total=225.50
CustomerID=CACTU OrderID=10782 Total=12.50
CustomerID=CACTU OrderID=10819 Total=477.00
CustomerID=CACTU OrderID=10881 Total=150.00
CustomerID=CACTU OrderID=11054 Total=305.00
CustomerID=CENTC OrderID=10259 Total=100.80
CustomerID=COMMI OrderID=10466 Total=216.00
CustomerID=COMMI OrderID=10969 Total=108.00
CustomerID=COMMI OrderID=11042 Total=405.75
CustomerID=CONSH OrderID=10462 Total=156.00
CustomerID=DRACD OrderID=10363 Total=447.20
CustomerID=DRACD OrderID=10391 Total=86.40
CustomerID=DRACD OrderID=10797 Total=420.00
CustomerID=DRACD OrderID=11067 Total=86.85
CustomerID=DUMON OrderID=10311 Total=268.80
CustomerID=DUMON OrderID=10609 Total=424.00
CustomerID=DUMON OrderID=10683 Total=63.00
CustomerID=ERNSH OrderID=10771 Total=344.00
CustomerID=FAMIA OrderID=10386 Total=166.00
CustomerID=FAMIA OrderID=10414 Total=224.83
CustomerID=FAMIA OrderID=10581 Total=310.00
CustomerID=FAMIA OrderID=10725 Total=287.80
CustomerID=FOLKO OrderID=10378 Total=103.20
CustomerID=FOLKO OrderID=10434 Total=321.12
CustomerID=FOLKO OrderID=10460 Total=176.10
CustomerID=FOLKO OrderID=10824 Total=250.80
CustomerID=FOLKO OrderID=10955 Total=74.40
CustomerID=FOLKO OrderID=10980 Total=248.00
CustomerID=FRANS OrderID=10422 Total=49.80
CustomerID=FRANS OrderID=10710 Total=93.50
CustomerID=FRANS OrderID=10753 Total=88.00
CustomerID=FRANS OrderID=10807 Total=18.40
CustomerID=FRANS OrderID=11060 Total=266.00
CustomerID=FURIB OrderID=10352 Total=136.30
CustomerID=FURIB OrderID=10491 Total=259.50
CustomerID=FURIB OrderID=10604 Total=230.85
CustomerID=FURIB OrderID=10963 Total=57.80
CustomerID=GALED OrderID=10366 Total=136.00
CustomerID=GALED OrderID=10426 Total=338.20
CustomerID=GALED OrderID=10568 Total=155.00
CustomerID=GALED OrderID=10887 Total=70.00
CustomerID=GALED OrderID=10928 Total=137.50
CustomerID=GODOS OrderID=10874 Total=310.00
CustomerID=GODOS OrderID=11037 Total=60.00
CustomerID=GOURL OrderID=10652 Total=318.84
CustomerID=GOURL OrderID=10777 Total=224.00
CustomerID=GOURL OrderID=10959 Total=131.75
CustomerID=GOURL OrderID=11049 Total=273.60
CustomerID=GREAL OrderID=10528 Total=392.20
CustomerID=GREAL OrderID=10589 Total=72.00
CustomerID=GREAL OrderID=10936 Total=456.00
CustomerID=GREAL OrderID=11006 Total=329.68
CustomerID=GREAL OrderID=11040 Total=200.00
CustomerID=GROSR OrderID=10785 Total=387.50
CustomerID=HANAR OrderID=10770 Total=236.25
CustomerID=HANAR OrderID=10925 Total=475.15
CustomerID=HILAA OrderID=10476 Total=180.48
CustomerID=HILAA OrderID=10613 Total=353.20
CustomerID=HILAA OrderID=10705 Total=378.00
CustomerID=HILAA OrderID=10863 Total=441.15
CustomerID=HILAA OrderID=10960 Total=265.35
CustomerID=HUNGC OrderID=10375 Total=338.00
CustomerID=HUNGC OrderID=10394 Total=442.00
CustomerID=HUNGC OrderID=10415 Total=102.40
CustomerID=HUNGC OrderID=10600 Total=479.80
CustomerID=ISLAT OrderID=10318 Total=240.40
CustomerID=ISLAT OrderID=10321 Total=144.00
CustomerID=ISLAT OrderID=10473 Total=230.40
CustomerID=ISLAT OrderID=10674 Total=45.00
CustomerID=ISLAT OrderID=10798 Total=446.60
CustomerID=KOENE OrderID=10323 Total=164.40
CustomerID=KOENE OrderID=10506 Total=415.80
CustomerID=KOENE OrderID=10542 Total=469.11
CustomerID=LACOR OrderID=10972 Total=251.50
CustomerID=LACOR OrderID=10973 Total=291.55
CustomerID=LAMAI OrderID=10358 Total=429.40
CustomerID=LAMAI OrderID=10371 Total=72.96
CustomerID=LAMAI OrderID=10425 Total=360.00
CustomerID=LAMAI OrderID=10454 Total=331.20
CustomerID=LAMAI OrderID=10610 Total=299.25
CustomerID=LAMAI OrderID=10631 Total=55.80
CustomerID=LAMAI OrderID=10832 Total=475.11
CustomerID=LAMAI OrderID=11051 Total=36.00
CustomerID=LAUGB OrderID=10495 Total=278.00
CustomerID=LAUGB OrderID=10620 Total=57.50
CustomerID=LAUGB OrderID=10810 Total=187.00
CustomerID=LAZYK OrderID=10482 Total=147.00
CustomerID=LAZYK OrderID=10545 Total=210.00
CustomerID=LEHMS OrderID=10279 Total=351.00
CustomerID=LEHMS OrderID=10534 Total=465.70
CustomerID=LEHMS OrderID=10891 Total=368.93
CustomerID=LETSS OrderID=10579 Total=317.75
CustomerID=LILAS OrderID=10381 Total=112.00
CustomerID=LILAS OrderID=10899 Total=122.40
CustomerID=LILAS OrderID=11065 Total=189.42
CustomerID=LILAS OrderID=11071 Total=484.50
CustomerID=LINOD OrderID=10405 Total=400.00
CustomerID=LINOD OrderID=10840 Total=211.20
CustomerID=LINOD OrderID=11014 Total=243.18
CustomerID=LONEP OrderID=10307 Total=424.00
CustomerID=LONEP OrderID=10317 Total=288.00
CustomerID=LONEP OrderID=10544 Total=417.20
CustomerID=LONEP OrderID=10662 Total=125.00
CustomerID=LONEP OrderID=10867 Total=98.40
CustomerID=LONEP OrderID=10883 Total=36.00
CustomerID=MAGAA OrderID=10275 Total=291.84
CustomerID=MAGAA OrderID=10467 Total=235.20
CustomerID=MAGAA OrderID=10754 Total=55.20
CustomerID=MAGAA OrderID=10950 Total=110.00
CustomerID=MAISD OrderID=11004 Total=295.38
CustomerID=MEREP OrderID=10376 Total=399.00
CustomerID=MEREP OrderID=10505 Total=147.90
CustomerID=MORGK OrderID=10699 Total=114.00
CustomerID=MORGK OrderID=10945 Total=245.00
CustomerID=NORTS OrderID=10517 Total=352.00
CustomerID=NORTS OrderID=10752 Total=252.00
CustomerID=NORTS OrderID=11057 Total=45.00
CustomerID=OCEAN OrderID=10409 Total=319.20
CustomerID=OCEAN OrderID=10531 Total=110.00
CustomerID=OCEAN OrderID=10898 Total=30.00
CustomerID=OTTIK OrderID=10508 Total=240.00
CustomerID=PERIC OrderID=10322 Total=112.00
CustomerID=PERIC OrderID=11073 Total=300.00
CustomerID=PICCO OrderID=10489 Total=439.20
CustomerID=PRINI OrderID=10336 Total=285.12
CustomerID=QUEDE OrderID=10261 Total=448.00
CustomerID=QUEDE OrderID=10291 Total=497.52
CustomerID=QUEDE OrderID=10794 Total=314.76
CustomerID=QUICK OrderID=10313 Total=182.40
CustomerID=RANCH OrderID=10448 Total=443.40
CustomerID=RANCH OrderID=11019 Total=76.00
CustomerID=REGGC OrderID=10288 Total=80.10
CustomerID=REGGC OrderID=10428 Total=192.00
CustomerID=REGGC OrderID=10562 Total=488.70
CustomerID=REGGC OrderID=10586 Total=23.80
CustomerID=REGGC OrderID=10655 Total=154.40
CustomerID=REGGC OrderID=11062 Total=406.40
CustomerID=RICAR OrderID=10299 Total=349.50
CustomerID=RICAR OrderID=10648 Total=372.38
CustomerID=RICSU OrderID=10951 Total=458.76
CustomerID=RICSU OrderID=11075 Total=498.10
CustomerID=ROMEY OrderID=10281 Total=86.50
CustomerID=ROMEY OrderID=10282 Total=155.40
CustomerID=ROMEY OrderID=10306 Total=498.50
CustomerID=ROMEY OrderID=10917 Total=365.89
CustomerID=ROMEY OrderID=11013 Total=361.00
CustomerID=SANTG OrderID=10520 Total=200.00
CustomerID=SAVEA OrderID=10815 Total=40.00
CustomerID=SIMOB OrderID=10341 Total=352.60
CustomerID=SIMOB OrderID=11074 Total=232.08
CustomerID=SPECD OrderID=10738 Total=52.35
CustomerID=SPECD OrderID=10907 Total=108.50
CustomerID=SPECD OrderID=11043 Total=210.00
CustomerID=SPLIR OrderID=10271 Total=48.00
CustomerID=SPLIR OrderID=10349 Total=141.60
CustomerID=SPLIR OrderID=10432 Total=485.00
CustomerID=SPLIR OrderID=10974 Total=439.00
CustomerID=SUPRD OrderID=10767 Total=28.00
CustomerID=THEBI OrderID=10310 Total=336.00
CustomerID=THEBI OrderID=10708 Total=180.40
CustomerID=THEBI OrderID=10992 Total=69.60
CustomerID=THECR OrderID=10775 Total=228.00
CustomerID=THECR OrderID=11003 Total=326.00
CustomerID=TOMSP OrderID=10438 Total=454.00
CustomerID=TOMSP OrderID=10446 Total=246.24
CustomerID=TOMSP OrderID=10548 Total=240.10
CustomerID=TORTU OrderID=10276 Total=420.00
CustomerID=TORTU OrderID=11069 Total=360.00
CustomerID=TRADH OrderID=10496 Total=190.00
CustomerID=TRAIH OrderID=10822 Total=237.90
CustomerID=VAFFE OrderID=10602 Total=48.75
CustomerID=VICTE OrderID=10334 Total=144.80
CustomerID=VICTE OrderID=10450 Total=425.12
CustomerID=VICTE OrderID=10478 Total=471.20
CustomerID=VICTE OrderID=10806 Total=439.60
CustomerID=VICTE OrderID=10843 Total=159.00
CustomerID=VINET OrderID=10295 Total=121.60
CustomerID=VINET OrderID=10737 Total=139.80
CustomerID=VINET OrderID=10739 Total=240.00
CustomerID=WANDK OrderID=10348 Total=363.60
CustomerID=WANDK OrderID=10651 Total=397.80
CustomerID=WARTH OrderID=10266 Total=346.56
CustomerID=WARTH OrderID=10412 Total=334.80
CustomerID=WARTH OrderID=10437 Total=393.00
CustomerID=WARTH OrderID=11025 Total=270.00
CustomerID=WELLI OrderID=10585 Total=142.50
CustomerID=WELLI OrderID=10809 Total=140.00
CustomerID=WELLI OrderID=10900 Total=33.75
CustomerID=WELLI OrderID=10905 Total=342.00
CustomerID=WHITC OrderID=10723 Total=468.45
CustomerID=WILMK OrderID=10248 Total=440.00
CustomerID=WILMK OrderID=10615 Total=120.00
CustomerID=WILMK OrderID=10673 Total=412.35
CustomerID=WILMK OrderID=10873 Total=336.80
CustomerID=WILMK OrderID=10910 Total=452.90
CustomerID=WOLZA OrderID=10374 Total=459.00
CustomerID=WOLZA OrderID=10792 Total=399.85
CustomerID=WOLZA OrderID=10870 Total=160.00
CustomerID=WOLZA OrderID=10906 Total=427.50
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +