LINQ multi-Table query

Source: Internet
Author: User

Loading editor...

1. onett has a field AA BB CC

2. twott has an ee ff bb Field

Two table connection queries,

 
List <multable> Mul = (from a in _ dB. onettt join B in _ dB. twottt on A. BB equals B. BB where a. BB! = "" Select new multable {AAA =. AA, BBB =. BB, eee = B. ee, fff = B. ff }). tolist <multable> (); foreach (multable item in Mul) console. writeline (item. AAA + item. BBB + item. EEE );
 class multable {Public String AAA = string. empty; Public String BBB = string. empty; Public String EEE = string. empty; Public String fff = string. empty; Public override string tostring () {return string. format ("AAA: {0}, BBB: {1}, eee: {2}, fff {3}", AAA, BBB, eee, fff );}} 
String [] weekdays = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday "}; // see the above Code, the ienumerable <string> weekdayswithlength is the explicit object, Here var weekdayswithlength is implicit object, which will convert by assign type. // var weekdayswithlength = from W in weekdays where W. length> 1 orderby W select W; string [] weekdayswithlength = (from W in weekdays where W. length> 1 orderby W select W ). toarray <string> (); // listbox1.items. clear (); foreach (string STR in weekdayswithlength) console. writeline (STR); List <car> mycars = new list <car> {new car {color = "Silver", make = "BMW", petname = "Henry ", speed = 100}, new car {color = "Tan", make = "BMW", petname = "Daisy", speed = 90}, new car {color = "black ", make = "VW", petname = "Mary", speed = 55}, new car {color = "Rust", make = "Yugo", petname = "clunker ", speed = 5}, new car {color = "white", make = "Ford", petname = "melvin", speed = 43 }}; list <car> fastcars = (from fcar in mycars where fcar. speed> 55 select fcar ). tolist <car> (); foreach (car c in fastcars) console. writeline (C. petname); // Nongeneric // non generic collection of car objects arraylist arcars = new arraylist {new car {color = "Silver", make = "BMW ", petname = "Henry", speed = 100}, new car {color = "Tan", make = "BMW", petname = "Daisy", speed = 90 }, new car {color = "black", make = "VW", petname = "Mary", speed = 55}, new car {color = "Rust ", make = "Yugo", petname = "clunker", speed = 5}, new car {color = "white", make = "Ford", petname = "melvin ", speed = 43 }}; // convert non generic car object collection to enumerable // ienumerable <car> mycars = arcars. oftype <car> (); // list <car> fastcars = (from fcar in mycars where fcar. speed> 55 select fcar ). tolist <car> (); // foreach (car c in fastcars) // console. writeline (C. petname );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.