1 / 45

Developing Windows and Web Applications using Visual Studio.NET

Developing Windows and Web Applications using Visual Studio.NET. Adam Stephensen. Session 1: Homework?. Session 1: Last week. What is .NET? What is .NET framework? What is the CLR? OOP Principles? Encapsulation, Abstraction, Inheritance, Polymorphism

joelle
Download Presentation

Developing Windows and Web Applications using Visual Studio.NET

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Developing Windows and Web Applications using Visual Studio.NET Adam Stephensen

  2. Session 1: Homework?

  3. Session 1: Last week • What is .NET? • What is .NET framework? • What is the CLR? • OOP Principles? • Encapsulation, Abstraction, Inheritance, Polymorphism • Classes, Objects, Properties, Events, Methods?

  4. Session 2: Overview Agenda • C# 3.0 & C# 4.0 Language Enhancements • What is LINQ? • LINQ Project Goals and Architecture • Writing LINQ • Data Binding with LINQ

  5. C# 3 2008

  6. C# 3.0 Language Enhancements • Local Variable Type Inference • Anonymous Type • Lambda Expressions • Extension methods • Object initializers • Query Expressions

  7. Local Variable Type Inference

  8. Anonymous Type • Fits with complex temporarily variables • E.g. I want a temp variable to hold username & password

  9. Lambda Expressions

  10. Extension methods Declaration • Extend existing classes by creating a static `helper` method Implementation

  11. Object Initializers • Object initializers allow values to be assigned to fields and properties as an object is instantiated.

  12. Query Expressions • Query expressions allow the querying of objects in a similar syntax to that of SQL

  13. C# 4 April 2010

  14. C# 4 Language Enhancements • The ‘dynamic‘ keyword • Optional parameters • Named parameters • Covariance and Contravariance

  15. Dynamic Keyword • When the dynamic keyword is used the ‘type’ of a variable is determined at runtime

  16. Optional Parameters • Optional parameters have a default specified and can be omitted when calling the method

  17. Named Parameters • Named parameters allow assignment of a value with an argument based on its name rather than the order in which it is passed

  18. .NET 3.5 • Auto Implemented Properties • Collection Initialisers (limited) • Named parameters • Optional parameters • Lambdas (limited) • Can span statements across multiple lines • Auto Implemented Properties • Collection Initialisers • Named parameters • Optional parameters • Lambdas • Can span statements across multiple lines

  19. .NET 4 • Auto Implemented Properties • Collection Initialisers • Named parameters • Optional parameters • Lambdas • Can span statements across multiple lines • Auto Implemented Properties • Collection Initialisers • Named parameters • Optional parameters • Lambdas • Can span statements across multiple lines

  20. Data access Show me the data!

  21. The Problem

  22. Problem

  23. What is LINQ? • First showcased at the American International Toy Fair in New York in 2005 • LINQ, a clever bluffing game

  24. What is LINQ? • LanguageINtegratedQuery • Allows you to easily query information about an object • LINQ to SQL: An ORM made by Microsoft • LINQ to Entities: Another ORM made by Microsoft • LINQ to XML: Query over XML • ...

  25. What is LINQ? • Language syntax • A library of extension methods • Lambda expressions • Anonymous types • A little magic

  26. .NET Framework 3.5

  27. LINQ - How does it solve the problem? • LINQ is a natural language extension, part of .NET 3.5 • Different data sources are queried with the same syntax. • Queries are strongly typed • Queries benefit from “Intellisense” • Applications becomes less error prone

  28. LINQ Project Goals • Unified programming model for any data type • Database Relational Data • XML Files • Collections & Arrays • Introduce more declarative syntax • Helps the system find the best execution strategy

  29. C# VB Others... LINQ Project Architecture .NET Language Integrated Query (LINQ) LINQ Enabled Data Sources LINQ Enabled ADO.NET LINQ to Objects LINQ to ??? LINQ to XML LINQ to Datasets LINQ to SQL LINQ to Entities <book> <title> <author/> <price /> </title> </book> Objects Database XML

  30. LINQ Query Syntax vs Method Syntax

  31. LINQ Query Syntax vs Method Syntax Query Syntax Extension Methods

  32. Standard Data Access Code stringstrSQL = “SELECT custID FROM Customers“; SqlCommandcmd = new SqlCommand(strSQL, cnn); SqlDataAdapteradAdapter = new SqlDataAdapter(cmd); DataSetdst = new DataSet(); adAdapter.Fill(dst);

  33. Code by LINQ NorthwindDataContext db = newNorthwindDataContext(); var customers = from c indb.Customers select c;

  34. How to use LINQ

  35. LINQ • Benefits from LINQ • LINQ data binding

  36. LINQ 2 SQL • Stored procedures are easier to work with • Relationship editor UI is nicer (more like SQL Server) • Performance • In a recent benchmark LINQ to SQL performed 5 times faster than LINQ to Entities

  37. LINQ 2 Entities • More refined ORM than LINQ to SQL • Many to Many relationships • Richer support for Inheritance • Validation • Update model from database • Mapping Editor

  38. What to choose? Do you know why you should choose "LINQ to Entities" over "LINQ to SQL"? http://www.ssw.com.au/ssw/Standards/Rules/RulesToBetterLINQ.aspx#WhyLINQtoEntitiesNotSQL

  39. Hot Tip • LINQ Pad • http://www.linqpad.net/

  40. Summary • C# 3.0 & C# 4.0 Language Enhancements • Local Variable Type Inference (var) • Anonymous Types • Lambda Expressions • Extension methods and Query Expressions • Object initializers • The ‘dynamic‘ keyword, • Optional and Named parameters • What is LINQ? • LINQ Project Goals and Architecture • Writing LINQ • LINQ Query Syntax • LINQ Method Syntax • Data Binding with LINQ • LINQ to SQL • LINQ to Entities

  41. Resources • Introduction to LINQhttp://msdn.microsoft.com/en-us/library/bb397897.aspx • Getting Started with LINQ in C#http://msdn.microsoft.com/en-us/library/bb397933.aspx • LINQ Term and more detailshttp://www.hookedonlinq.com/ • LinqPadhttp://www.linqpad.net/ • Linq tutorialshttp://language-integrated-query.com/

  42. Resources • LINQ Query Syntax versus Method Syntax http://msdn.microsoft.com/en-us/library/bb397947.aspx • Object Initializershttp://msdn.microsoft.com/en-us/library/bb384062.aspx • Query Expression Basicshttp://msdn.microsoft.com/en-us/library/bb384065.aspx • Hooked in LINQHookedOnLINQ.com

  43. What's next?

  44. 3things… • AdamStephensen@ssw.com.au • http://adamstephensen.com/ • twitter.com/adamstephensen

  45. Thank You! Gateway Court Suite 10 81 - 91 Military Road Neutral Bay, Sydney NSW 2089 AUSTRALIA ABN: 21 069 371 900 Phone: + 61 2 9953 3000 Fax: + 61 2 9953 3105 info@ssw.com.auwww.ssw.com.au

More Related