Chapter 11.  Large amounts of data are often stored in a database—an organized collection of data.  A database management system (DBMS) provides mechanisms.

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

Intro to Scala Lists. Scala Lists are always immutable. This means that a list in Scala, once created, will remain the same.
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
LINQ and Collections An introduction to LINQ and Collections.
Extension Methods, Anonymous Types LINQ Query Keywords, Lambda Expressions Svetlin Nakov Telerik Corporation
Chapter 41 Variables and JSP Control Structures JavaServer Pages By Xue Bai.
5/17/ Programming Constructs... There are several types of programming constructs in JAVA. - If-else construct or ternary operator - while - do-while.
Instructor: Craig Duckett CASE, ORDER BY, GROUP BY, HAVING, Subqueries
Programming with Collections Collections in Java Using Arrays Week 9.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 8 Arrays.
©2004 Brooks/Cole Chapter 8 Arrays. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Sometimes we have lists of data values that all need to be.
Arrays Data Structures - structured data are data organized to show the relationship among the individual elements. It usually requires a collecting mechanism.
1 CSCE 1030 Computer Science 1 Arrays Chapter 7 in Small Java.
2.3 Cool features in C# academy.zariba.com 1. Lecture Content 1.Extension Methods 2.Anonymous Types 3.Delegates 4.Action and Func 5.Events 6.Lambda Expressions.
Switch Statements Comparing Exact Values. 2 The Switch Statement The switch statement provides another way to decide which statement to execute next The.
A tour of new features introducing LINQ. Agenda of LINQ Presentation We have features for every step of the way LINQ Fundamentals Anonymous Functions/Lambda.
CORE 2: Information systems and Databases STORAGE & RETRIEVAL 2 : SEARCHING, SELECTING & SORTING.
Day 4 Objectives Constructors Wrapper Classes Operators Java Control Statements Practice the language.
XML files (with LINQ). Introduction to LINQ ( Language Integrated Query ) C#’s new LINQ capabilities allow you to write query expressions that retrieve.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Databases and LINQ Visual Basic 2010 How to Program 1.
Using the Select Case Statement and the MsgBox Function (Unit 8)
Lambdas and Streams. Functional interfaces Functional interfaces are also known as single abstract method (SAM) interfaces. Package java.util.function.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
Chapter 2: Using Data.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Arrays.
Introduction to Arrays in Java Corresponds with Chapter 6 of textbook.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
Lec 6 Data types. Variable: Its data object that is defined and named by the programmer explicitly in a program. Data Types: It’s a class of Dos together.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
 Although VERY commonly used, arrays have limited capabilities  A List is similar to an array but provides additional functionality, such as dynamic.
Introduction to LINQ Chapter 11. Introduction Large amounts of data are often stored in a database—an organized collection of data. A database management.
Switch Statements Comparing Exact Values. The Switch Statement: Syntax The switch statement provides another way to decide which statement to execute.
Chapter 4 Introduction to Classes, Objects, Methods and strings
CSCI 3328 Object Oriented Programming in C# Chapter 8: LINQ and Generic Collections 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX.
Object Oriented Programming Generic Collections and LINQ Dr. Mike Spann
XML Query: xQuery Reference: Xquery By Priscilla Walmsley, Published by O’Reilly.
CSCI 3327 Visual Basic Chapter 8: Introduction to LINQ and Collections UTPA – Fall 2011.
Inside LINQ to Objects How LINQ to Objects work Inside LINQ1.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
CSCI 3328 Object Oriented Programming in C# Chapter 8: LINQ and Generic Collections – Exercises 1 Xiang Lian The University of Texas – Pan American Edinburg,
CSCI 3328 Object Oriented Programming in C# Chapter 12: Databases and LINQ – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg,
Database: SQL, MySQL, LINQ and Java DB © by Pearson Education, Inc. All Rights Reserved.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
An Introduction to Java – Part 1 Erin Hamalainen CS 265 Sec 001 October 20, 2010.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
LINQ Language Integrated Query LINQ1. LINQ: Why and what? Problem Many data sources: Relational databases, XML, in-memory data structures, objects, etc.
Arrays (part 2) 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
LINQ and Lambda Expressions Telerik Software Academy LINQ Overview.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
Chapter 9 Working with Databases. Copyright © 2011 Pearson Addison-Wesley Binding to ListBox and ComboBox Controls List and combo boxes are frequently.
Creating Database Objects
Visual Basic 2010 How to Program
Arrays Chapter 7.
Introduction to LINQ and Generic Collections
Visual Basic 2010 How to Program
Chapter 3 Introduction to Classes, Objects Methods and Strings
Introduction to LINQ Chapter 11 10/28/2015 Lect 4 CT1411.
Introduction to LINQ Chapter 11.
Object Oriented Programming in java
Chapter 6 Control Statements: Part 2
Type & Typeclass Syntax in function
Arrays Chapter 7.
Methods.
Arrays Part 2.
CSCI 3328 Object Oriented Programming in C# Chapter 8: LINQ and Generic Collections – Exercises UTPA – Fall 2012 This set of slides is revised from lecture.
Creating Database Objects
Presentation transcript:

Chapter 11

 Large amounts of data are often stored in a database—an organized collection of data.  A database management system (DBMS) provides mechanisms for storing, organizing, retrieving and modifying data contained in the database.  Today’s most popular database systems are relational databases.  A language called Structured Query Language (SQL) is an international standard used with relational databases to perform queries (that is, to request information that satisfies given criteria) and to manipulate data.

 For years, programs that accessed a relational database passed SQL queries as String s to the database management system then processed the results.  Microsoft developed LINQ (Language Integrated Query) to enable you to write query expressions similar to SQL queries that retrieve information from a wide variety of data sources—not just relational databases—using a common syntax that is built into Visual Basic.

 We use LINQ to Objects to query the contents of arrays, selecting elements that satisfy a set of conditions—this is known as filtering.  We also use LINQ to Objects to perform common array manipulations such as sorting an array.  Figure 11.1 shows the types of LINQ queries.

 Primitive types are the basic type of data ◦ Byte, short, int, long, float, double, boolean, char ◦ Primitive variables store primitive values.  LINQ allows you to look at collections of data, extract information and manipulate data.

 LINQ query operations consist of three actions: 1. Obtain the data source or sources. 2. Create the query. 3. Execute the query

' Data source. Dim numbers() As Integer={0,1,2,3,4,5,6} ' Query creation. Dim evensQuery = From num In numbers Where num Mod 2 = 0 Select num ' Query execution. For Each number In evensQuery Console.Write(number & " ") Next Output:

 Our first LINQ query begins with a From clause which specifies a range variable ( num ) and the data source to query (the array numbers ).  The range variable represents each item in the data source, much like the control variable in a For Each … Next statement.  If the condition in the Where clause evaluates to True, the element is selected—that is, it’s included in the collection of Integer s that represents the query results.  Here, the Integer s in the array are included only if they’re divisible by 2.

 For each item in the data source, the Select clause determines what value appears in the results.  In this case, it’s the Integer that the range variable currently represents.  The Select clause is usually placed at the end of the query for clarity, though it may be placed after the From clause and before other clauses, or omitted.  If omitted, the range variable is implicitly selected.  The Select clause can transform the selected items—for example, Select value * 2 in this example would have multiplied each selected value in the result by 2.

 You can use a For Each … Next statement to iterate over the results of any LINQ query.

 Sorting LINQ Query Results ◦ The LINQ query in the above example selects the elements of the array values and returns an IEnumerable object containing a sorted copy of the elements. Dim values() As Integer = {2,9,5,0,3,7,1,4,8,6} Dim sorted = From value In values Order By value Select value

 The Order By clause sorts the query results in ascending order.  You can use the Descending modifier in the Order By clause to sort query results in descending order.  An Ascending modifier also exists but is rarely used, because it’s the default.  You can use the Order By clause only for values that can be compared to one another.  The Order By clause supports values of any type that implements the interface IComparable, such as the primitive numeric types and String.  Such types provide a CompareTo method.

 LINQ is not limited to querying arrays of primitive types.  It can be used with most data types.

 When you type the name of an IEnumerable object (such as an array or the result of a LINQ query) then type the dot (. ) separator, the list of the methods and properties that can be used with that object are shown.  Some of the methods are so-called extension methods.  For example, if you have an array of Double s called numbers and you want to calculate the average of its values, you can simply call the Average extension method, as in numbers.Average().  Some of IEnumerable ’s 45 extension methods are shown in Fig

 LINQ uses a technique called deferred execution—a query executes only when you iterate over the results, not when the query is defined.  This allows you to create a query once and execute it many times.  If you make any changes to the data in a LINQ query’s data source, the next time you iterate over the query’s results, the query will process the current data in the data source.

 Figure 11.7 filters an array of String s by searching for those that begin with "r".  Initially the array (lines 8–9) contains two such String s.  Later in the program we modify the array then reexecute the LINQ query to demonstrate deferred execution.  This example also demonstrates how to transform the items that match the Where clause—in this case, each matching String is converted to uppercase in the query result.