• Like
Linqtosql 090629035715 Phpapp01
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Linqtosql 090629035715 Phpapp01

  • 676 views
Published

 

Published in Technology , Business
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
676
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
19
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. devInTown
    Chan Ming Man
    C# MVP
    http://chanmingman.spaces.live.com
    Level 200
  • 2. devInTown
    CRUD Using LINQ (Language Integrated Query)
    Chan Ming Man
    C# MVP
    http://chanmingman.spaces.live.com
    Level 200
  • 3. Agenda
    The object model challenges the relational model
    What is LINQ?
    LINQ to SQL
  • 4. Helpful Experience
    Visual Studio 2008 C# Express
    SQL Server 2005
    ADO.NET
  • 5. The object model challenges the relational model
    The relational model has been fantastically successful in a wide variety of application areas. However, it is not problem free. The problems have been made more visible by the rise in popularity of object-oriented programming languages such as C++, Java, and C#.
  • 6. Data…its our job
    Querying and manipulating data has always been a fundamental part of our jobs as programmers
    Data formats change, but core needs are the same
  • 7. Data Access(DBASE circa 1980s)
    USE empl
    REPLACE ALL salary WITH (salary * 1.1) FOR supervises > 0
    LIST ALL fname, lname, salary FOR Supervises > 0
    Data querying and manipulation a core part of the programming model experience
    Certainly had limitations, but it sure was useful
  • 8. But Challenges Still Remain…
    How to retrieve non-relational data?
    XML, RSS, Web Services, REST, AD, Files, etc.
    How to interact with plain old objects?
    How do you interact and query custom domain models?
    How to enable rich data shaping & transformations?
    Support flexible query composition (that is fast!)
    How to enable clean code in both a strongly typed and dynamic language world?
  • 9. LINQ
    Query, Set, and Transform Operations for .NET
    Makes querying data a core programming concept
    Works with all types and shapes of data
    Relational databases
    XML
    Plain old Objects
    Works with all .NET languages
    New VB and C# have integrated language support
  • 10. Queries integrated with code (C#/VB)
    What is LINQ?
    Strongly-typed
    Benefits from IntelliSense
    Collections of objects
    Relational data
    XML
    Unified Querying
    Language INtegrated Queries
  • 11. LINQ Architecture
    C# 3.0
    VB 9.0
    Others…
    .NET Language-Integrated Query (LINQ)
    LINQ Enabled Data Sources
    LINQ enabled ADO.NET
    LINQ
    to
    Entities
    LINQ
    To
    SQL
    LINQ
    to
    XML
    LINQ
    To
    Dataset
    LINQ
    To
    Objects
    XML
    Objects
    Relational Data
    11
    ©2008 Pavel Yosifovich
  • 12. Where is LINQ to SQL in MVC?
    Model
    LINQ
    To
    SQL
    Controller
    View
  • 13. LINQ to SQL
    Application
    from c in db.Customers
    where c.City == "London"
    select c.CompanyName
    db.Customers.Add(c1);
    c2.City = “Seattle";
    db.Customers.Remove(c3);
    LINQ Query
    Objects
    SubmitChanges()
    LINQ to SQL
    SQL Query
    Rows
    DML or Stored Procedures
    SELECT CompanyName
    FROM Cust
    WHERE City = 'London'
    INSERT INTO Customers…
    UPDATE Customers …DELETE FROM Customers …
    SQL Server
  • 14. LINQ to SQL fully support CRUD
    C = Create = Insert
    R = Read = Select
    U = Update
    D = Delete
  • 15. Create
    LINQ
    varnewCustomer = new Customer {
    CustomerID = "DLEAP",
    CompanyName = "DevLeap",
    Country = "Italy" };
    db.Customers.InsertOnSubmit(newCustomer);
    SQL
    INSERT INTO [Customers](CustomerID, CompanyName, ...)
    VALUES("DLEAP", "DevLeap", ...)
  • 16. Read
    LINQ
    var query =
    from c in Customers
    where c.Country == "USA"
    && c.State == "WA"
    select new {c.CustomerID, c.CompanyName, c.City };
    SQL
    SELECT CustomerID, CompanyName, City
    FROM Customers
    WHERE Country = 'USA'
    AND Region = 'WA'
  • 17. Update
    LINQ
    Customer cust = db.Customers.Single(p => p.CustomerID == 11111);
    cust.LastName = “Thomas ";
    db.SubmitChanges();
    SQL
    UPDATE Customer LastName = “Thomas "
    SET WHERE CustomerID == 11111
  • 18. Delete
    LINQ
    varoldDetail = db.Order_Details.Single(
    od => od.OrderID == 10422
    && od.ProductID == 26);
    db.Order_Details.DeleteOnSubmit(oldDetail);
    SQL
    DELETE FROM [dbo].[Order Details]
    WHERE [OrderID] = 10422 AND [ProductID] = 26 AND ...
  • 19. Demo …
  • 20. Resources - LINQ
    MSDN Developer Center
    http://msdn2.microsoft.com/en-us/netframework/aa904594.aspx
    LINQ Forum
    http://forums.microsoft.com/msdn/showforum.aspx?forumid=123
    Channel9 Linq Videos
    http://channel9.msdn.com/tags/linq
    Blogs
    Scott Guthrie
    http://weblogs.asp.net/scottgu/archive/2007/04/21/new-orcas-language-feature-query-syntax.aspx
    Charlie Calvert
    http://blogs.msdn.com/charlie/archive/2006/10/05/Links-to-LINQ.aspx
    LINQ HOL
    C# 3.0 Enhancements & LINQ (English)
  • 21. © 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.
    The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.