Makeup Querying Collections
|
filtering a collection [LINQ] static void Main() |
LINQ is what C#3.5 is all about at its heart. In particular, it contains query expressions that allow a declarative style for creating queries on various data sources.
Actually, LINQ is that while query expressions are not particularly suitable for simple task,they're very, very good for more complicated situations that would be hard to read if written out in the equivalent method calls.
Now let's look at a code to join the sample products with the sample suppliers (obviously based on the supplier ID), apply the same price filter as before to the products, sort by supplier name and then product name, and print out the name of both supplier and product for each match.
*So , in earlier versions of C# it would have been a nightmare to implement. In LINQ, it's almost trivial!
|
Joing ,filtering , ordering, and projecting It looks remarkably like SQL, This is the reaction of many people on first hearing. |
|
So, we maybe getting data from any number of sources:XML Well,the xml file is simple enough, but what's the best way of extracting the data from it? Query it? Join on it? OK, continue |
|
Shows how much work we have to do in LINQ to XML
Keyword: XDocument,Descendants,Attribute Well, it's not quite as straightforward, because we need to tell the system how it should understand the data(in terms of what attributes should be used as what types) |
|
Ok, Let us put the data where it's much more likely to be- in a database. Shows how much work we have to do in LINQ to SQL Step one: Create dbml Step two: Haulage DataTable Step three: Looking
This code issues a database request, which is basically the query transalted into SQL.
For instance: => LINQ to Amazon Wow LINQ to Everything So much for this! |