Presentation is loading. Please wait.

Presentation is loading. Please wait.

04 | Data Acess Technologies

Similar presentations


Presentation on theme: "04 | Data Acess Technologies"— Presentation transcript:

1 04 | Data Acess Technologies
Bruno Terkaly | Technical Evangelist Bret Stateham | Technical Evangelist

2 Module Overview ADO.NET LINQ (Language Integrated Query)
XML (Extensible Markup Language) LINQ to XML

3 ADO.NET

4 Basic ADO.NET Objects Connection* DataReader*
Command* (SELECT, …) Results string constr = "Server=server;Database=db;User ID=user;Password=pwd;..."; using(SqlConnection connection = new SqlConnection(constr)) { string query = "SELECT TOP 10 PositionID, ReportedAt, Latitude, Longitude FROM dbo.Positions;"; using (SqlCommand cmd = new SqlCommand(query,connection)) { connection.Open(); using (SqlDataReader rdr = command.ExecuteReader()) while(rdr.Read()) string position = string.Format("{0},{1},{2},{3}",rdr.GetInt32(0),rdr.GetDateTime(1),rdr.GetFloat(2),rdr.GetFloat(3)); Console.WriteLine(position); } * ADO.NET Provider Specific: SqlConnection, SqlCommand, SqlDataReader

5 ADO.NET Providers

6 DataTable and DataAdapter
Connection* DataTable DataAdapter* Fill() SelectCommand* Update() InsertCommand* UpdateCommand* DeleteCommand* * ADO.NET Provider Specific: SqlConnection, SqlCommand, SqlDataAdapter

7 DataSets Connection* DataSet DataAdapter(s)*
Commands* Fill/Update * ADO.NET Provider Specific: SqlConnection, SqlCommand, SqlDataAdapter

8 Querying data with ADO.NET

9 LINQ (Language-INtegrated Query)

10 Data Sources & Client Access
Relational DBs XML Collections ADO.NET / SQL DOM / XPath C#

11 LINQ to Objects & IEnumerable
LINQ to the Rescue! Relational DBs XML Collections LINQ LINQ to Entities & IQueryable LINQ to XML LINQ to Objects & IEnumerable C#

12 What is LINQ? A way to query data in memory
A collection of extension methods to IEnumerable Queries are “composable” and don’t execute until data is accessed. Allows querying, filtering, aggregating, joining, collections in memory A way to ship queries across application layers IQueryable represents the intention of the query Can be shipped between application tiers (service <> client) Service can provide the initial query Client can further “compose” the query (filter, sort, etc) Client passes the composed query back to the service The service returns the data as specified by the query. Cool!

13 LINQ to Objects

14 XML (Extensible Markup Language)

15 Good Old XML Read all about it: www.w3.org/xml (seriously)
<Positions> <Position PositionID="1"> <ReportedAt> T22:51:00</ReportedAt> <Region>North Carolina</Region> <Country>United States</Country> <Latitude> </Latitude> <Longitude> </Longitude> </Position> <Position PositionID="2"> <ReportedAt> T22:54:00</ReportedAt> <Latitude> </Latitude> <Longitude> </Longitude> <Position PositionID="3"> <ReportedAt> T17:17:00</ReportedAt> <Latitude> </Latitude> <! > </Positions> Read all about it: (seriously) Family of related standards XML XML Schemas XPath XQuery XSLT (Transformations) XSL-FO

16 Working with XML in Code
System.Xml XmlDocument for Document Object Model (DOM) based operations XmlReader for SAX (streaming) based operations Create XML with XmlDocument, XmlElement, XmlAttribute… Can save / load XML from files Can parse XML from strings

17 System.Xml Namespace XmlDocument XmlDeclaration XmlComment XmlElement
<?xml version="1.0" ?> <!– Sample Position --> <Position>…</Position> <Position PositionID="1"> <Latitude> </Latitude> <Longitude> </Longitude> </Position> </Positions> XmlDocument XmlDeclaration XmlComment XmlElement XmlAttribute XmlText XmlNode

18 DOM Based XML Processing

19 LINQ to XML

20 LINQ to Objects & IEnumerable
LINQ to the Rescue! Relational DBs XML Collections LINQ LINQ to Entities & IQueryable LINQ to XML LINQ to Objects & IEnumerable C#

21 System.Xml.Linq Namespace
XDocument <?xml version="1.0" ?> <!– Sample Position --> <Position>…</Position> <Position PositionID="1"> <Latitude> </Latitude> <Longitude> </Longitude> </Position> </Positions> XDeclaration XComment XElement XAttribute XText

22 LINQ to XML

23


Download ppt "04 | Data Acess Technologies"

Similar presentations


Ads by Google