SlideShare a Scribd company logo
devInTownChan Ming ManC# MVPhttp://chanmingman.spaces.live.comLevel 200
devInTownCRUD Using LINQ (Language Integrated Query)Chan Ming ManC# MVPhttp://chanmingman.spaces.live.comLevel 200
AgendaThe object model challenges the relational modelWhat is LINQ?LINQ to SQL
Helpful ExperienceVisual Studio 2008 C# ExpressSQL Server 2005 ADO.NET
The object model challenges the relational modelThe 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#.
Data…its our jobQuerying and manipulating data has always been a fundamental part of our jobs as programmersData formats change, but core needs are the same
Data Access(DBASE circa 1980s)USE empl  REPLACE ALL salary WITH (salary * 1.1) FOR supervises > 0  LIST ALL fname, lname, salary FOR Supervises > 0Data querying and manipulation a core part of the programming model experienceCertainly had limitations, but it sure was useful
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?
LINQQuery, Set, and Transform Operations for .NETMakes querying data a core programming concept Works with all types and shapes of dataRelational databasesXMLPlain old ObjectsWorks with all .NET languagesNew VB and C# have integrated language support
Queries integrated with code (C#/VB)What is LINQ?Strongly-typedBenefits from IntelliSenseCollections of objectsRelational dataXMLUnified QueryingLanguage INtegrated Queries
LINQ ArchitectureC# 3.0VB 9.0Others….NET Language-Integrated Query (LINQ)LINQ Enabled Data SourcesLINQ enabled ADO.NETLINQ to EntitiesLINQ ToSQLLINQ toXMLLINQ ToDatasetLINQ ToObjectsXMLObjectsRelational Data11©2008 Pavel Yosifovich
Where is LINQ to SQL in MVC?ModelLINQ ToSQLControllerView
LINQ to SQLApplicationfrom c in db.Customerswhere c.City == "London"select c.CompanyNamedb.Customers.Add(c1);c2.City = “Seattle";db.Customers.Remove(c3);LINQ QueryObjectsSubmitChanges()LINQ to SQLSQL QueryRowsDML or Stored ProceduresSELECT CompanyNameFROM CustWHERE City = 'London'INSERT INTO Customers…UPDATE Customers …DELETE FROM Customers …SQL Server
LINQ to SQL fully support CRUDC = Create = InsertR = Read = SelectU = UpdateD = Delete
CreateLINQvarnewCustomer = new Customer {CustomerID = "DLEAP",CompanyName = "DevLeap",Country = "Italy" };db.Customers.InsertOnSubmit(newCustomer);SQLINSERT INTO [Customers](CustomerID, CompanyName, ...)VALUES("DLEAP", "DevLeap", ...)
ReadLINQvar query =from c in Customerswhere c.Country == "USA"&& c.State == "WA"select new {c.CustomerID, c.CompanyName, c.City };SQLSELECT CustomerID, CompanyName, CityFROM CustomersWHERE Country = 'USA'AND Region = 'WA'
UpdateLINQCustomer cust = db.Customers.Single(p => p.CustomerID == 11111);cust.LastName = “Thomas ";db.SubmitChanges();SQLUPDATE Customer LastName = “Thomas "SET WHERE CustomerID == 11111
DeleteLINQvaroldDetail = db.Order_Details.Single(od => od.OrderID == 10422&& od.ProductID == 26);db.Order_Details.DeleteOnSubmit(oldDetail);SQLDELETE FROM [dbo].[Order Details]WHERE [OrderID] = 10422 AND [ProductID] = 26 AND ...
Demo …
Resources - LINQMSDN Developer Centerhttp://msdn2.microsoft.com/en-us/netframework/aa904594.aspxLINQ Forumhttp://forums.microsoft.com/msdn/showforum.aspx?forumid=123Channel9 Linq Videoshttp://channel9.msdn.com/tags/linqBlogsScott Guthrie http://weblogs.asp.net/scottgu/archive/2007/04/21/new-orcas-language-feature-query-syntax.aspxCharlie Calvert http://blogs.msdn.com/charlie/archive/2006/10/05/Links-to-LINQ.aspxLINQ HOLC# 3.0 Enhancements & LINQ (English)
© 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.

More Related Content

PPT
Introduction Of Linq , ASP.NET Training Ahmedabad, ASP.NET Course Ahmedabad
KEY
Introducing LINQ
PPTX
GraphQL, Redux, and React
PDF
London React August - GraphQL at The Financial Times - Viktor Charypar
PDF
GraphQL in an Age of REST
PDF
PDF
OrientDB - Voxxed Days Berlin 2016
PDF
GraphQL + relay
Introduction Of Linq , ASP.NET Training Ahmedabad, ASP.NET Course Ahmedabad
Introducing LINQ
GraphQL, Redux, and React
London React August - GraphQL at The Financial Times - Viktor Charypar
GraphQL in an Age of REST
OrientDB - Voxxed Days Berlin 2016
GraphQL + relay

Viewers also liked (6)

PPT
Introduction to Linq
PPT
Object Relational Mapping with LINQ To SQL
PPT
C# 3.0 Language Innovations
PPTX
L16 Object Relational Mapping and NoSQL
PPTX
Bridge Design Pattern
PDF
Object Relational Mapping with Dapper (Micro ORM)
Introduction to Linq
Object Relational Mapping with LINQ To SQL
C# 3.0 Language Innovations
L16 Object Relational Mapping and NoSQL
Bridge Design Pattern
Object Relational Mapping with Dapper (Micro ORM)
Ad

Similar to Dev-In-Town:Linq To Sql by Chan Ming Man (20)

PPTX
Linqtosql 090629035715 Phpapp01
PPT
LINQ-Introduction.ppt
PDF
Litwin linq
DOCX
Linq in C#
PDF
Intake 37 linq3
PPT
Linq in C# 3.0: An Overview
PPTX
ORM - Ivan Marković
PPTX
Think in linq
PPT
PDF
Asp.Net 3.5 Part 2
PPTX
Linq to sql
PDF
The LINQ Between XML and Database
PPTX
Understanding LINQ in C#
PPT
MySQL, LINQ and the ADO_NET Entity Framework Presentation.ppt
PPT
PPT
Linq intro
PPTX
SQL ttrain wrwrwrw wwrw wwrrrwrwrwrwwrwr.pptx
PPT
LINQ 2 SQL Presentation To Palmchip And Trg, Technology Resource Group
PPTX
LINQ PPT.pptx
Linqtosql 090629035715 Phpapp01
LINQ-Introduction.ppt
Litwin linq
Linq in C#
Intake 37 linq3
Linq in C# 3.0: An Overview
ORM - Ivan Marković
Think in linq
Asp.Net 3.5 Part 2
Linq to sql
The LINQ Between XML and Database
Understanding LINQ in C#
MySQL, LINQ and the ADO_NET Entity Framework Presentation.ppt
Linq intro
SQL ttrain wrwrwrw wwrw wwrrrwrwrwrwwrwr.pptx
LINQ 2 SQL Presentation To Palmchip And Trg, Technology Resource Group
LINQ PPT.pptx
Ad

More from Quek Lilian (20)

PDF
Sgug print copy pdf ll
PDF
Singapore MVP gazette
PPTX
Expression studio overview_MVP Kok Chiann
PPTX
Installation and Adminstration of AD_MVP Padman
PPTX
Exchange server 2010 overview_MVP Padman
PPTX
Installing managing windows server 2008 r2_MVP Shaminda
PPTX
SharePoint 2010 launch_MVP Sampath Perera
PPT
NUS exam 70-432_MVP Choirul Amri
PDF
Windows server 2008 r2 and web platform_MVP Fajar
PPTX
Express web development with visual studio 2010 express_MVP Ronald Rajagukguk
PPTX
Windows 7 For Students_MVP Jabez Gan
PPTX
Lkw Security Part 1_MVPs Azra & Sanjay
PDF
Sql2008 R2 Dw (Phua Chiu Kiang)
PPTX
Commercial Launch Win7 Dev Chalermvong
PPTX
Commercial Launch Win7 Dev Chalermvong
PPTX
Unveiling Share Point 2010_MVP Joy Pradeep
PPTX
Unveiling Share Point 2010_MVP Joy Pradeep
PPTX
Introduction To Virtualization_MVP Jabez Gan
PPTX
Vs2010 Aspnet MSP Bootcamp_MVP Ngan Seok Chern
PPTX
Windows 2008 Active Directory Branch office Management_MVP Sampath Perera
Sgug print copy pdf ll
Singapore MVP gazette
Expression studio overview_MVP Kok Chiann
Installation and Adminstration of AD_MVP Padman
Exchange server 2010 overview_MVP Padman
Installing managing windows server 2008 r2_MVP Shaminda
SharePoint 2010 launch_MVP Sampath Perera
NUS exam 70-432_MVP Choirul Amri
Windows server 2008 r2 and web platform_MVP Fajar
Express web development with visual studio 2010 express_MVP Ronald Rajagukguk
Windows 7 For Students_MVP Jabez Gan
Lkw Security Part 1_MVPs Azra & Sanjay
Sql2008 R2 Dw (Phua Chiu Kiang)
Commercial Launch Win7 Dev Chalermvong
Commercial Launch Win7 Dev Chalermvong
Unveiling Share Point 2010_MVP Joy Pradeep
Unveiling Share Point 2010_MVP Joy Pradeep
Introduction To Virtualization_MVP Jabez Gan
Vs2010 Aspnet MSP Bootcamp_MVP Ngan Seok Chern
Windows 2008 Active Directory Branch office Management_MVP Sampath Perera

Recently uploaded (20)

PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Encapsulation theory and applications.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
MYSQL Presentation for SQL database connectivity
PPT
Teaching material agriculture food technology
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
cuic standard and advanced reporting.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Big Data Technologies - Introduction.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Advanced methodologies resolving dimensionality complications for autism neur...
NewMind AI Weekly Chronicles - August'25 Week I
Per capita expenditure prediction using model stacking based on satellite ima...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Encapsulation theory and applications.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Network Security Unit 5.pdf for BCA BBA.
MYSQL Presentation for SQL database connectivity
Teaching material agriculture food technology
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
MIND Revenue Release Quarter 2 2025 Press Release
Unlocking AI with Model Context Protocol (MCP)
cuic standard and advanced reporting.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Big Data Technologies - Introduction.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Electronic commerce courselecture one. Pdf
Encapsulation_ Review paper, used for researhc scholars

Dev-In-Town:Linq To Sql by Chan Ming Man

  • 1. devInTownChan Ming ManC# MVPhttp://chanmingman.spaces.live.comLevel 200
  • 2. devInTownCRUD Using LINQ (Language Integrated Query)Chan Ming ManC# MVPhttp://chanmingman.spaces.live.comLevel 200
  • 3. AgendaThe object model challenges the relational modelWhat is LINQ?LINQ to SQL
  • 4. Helpful ExperienceVisual Studio 2008 C# ExpressSQL Server 2005 ADO.NET
  • 5. The object model challenges the relational modelThe 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 jobQuerying and manipulating data has always been a fundamental part of our jobs as programmersData 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 > 0Data querying and manipulation a core part of the programming model experienceCertainly 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. LINQQuery, Set, and Transform Operations for .NETMakes querying data a core programming concept Works with all types and shapes of dataRelational databasesXMLPlain old ObjectsWorks with all .NET languagesNew VB and C# have integrated language support
  • 10. Queries integrated with code (C#/VB)What is LINQ?Strongly-typedBenefits from IntelliSenseCollections of objectsRelational dataXMLUnified QueryingLanguage INtegrated Queries
  • 11. LINQ ArchitectureC# 3.0VB 9.0Others….NET Language-Integrated Query (LINQ)LINQ Enabled Data SourcesLINQ enabled ADO.NETLINQ to EntitiesLINQ ToSQLLINQ toXMLLINQ ToDatasetLINQ ToObjectsXMLObjectsRelational Data11©2008 Pavel Yosifovich
  • 12. Where is LINQ to SQL in MVC?ModelLINQ ToSQLControllerView
  • 13. LINQ to SQLApplicationfrom c in db.Customerswhere c.City == "London"select c.CompanyNamedb.Customers.Add(c1);c2.City = “Seattle";db.Customers.Remove(c3);LINQ QueryObjectsSubmitChanges()LINQ to SQLSQL QueryRowsDML or Stored ProceduresSELECT CompanyNameFROM CustWHERE City = 'London'INSERT INTO Customers…UPDATE Customers …DELETE FROM Customers …SQL Server
  • 14. LINQ to SQL fully support CRUDC = Create = InsertR = Read = SelectU = UpdateD = Delete
  • 15. CreateLINQvarnewCustomer = new Customer {CustomerID = "DLEAP",CompanyName = "DevLeap",Country = "Italy" };db.Customers.InsertOnSubmit(newCustomer);SQLINSERT INTO [Customers](CustomerID, CompanyName, ...)VALUES("DLEAP", "DevLeap", ...)
  • 16. ReadLINQvar query =from c in Customerswhere c.Country == "USA"&& c.State == "WA"select new {c.CustomerID, c.CompanyName, c.City };SQLSELECT CustomerID, CompanyName, CityFROM CustomersWHERE Country = 'USA'AND Region = 'WA'
  • 17. UpdateLINQCustomer cust = db.Customers.Single(p => p.CustomerID == 11111);cust.LastName = “Thomas ";db.SubmitChanges();SQLUPDATE Customer LastName = “Thomas "SET WHERE CustomerID == 11111
  • 18. DeleteLINQvaroldDetail = db.Order_Details.Single(od => od.OrderID == 10422&& od.ProductID == 26);db.Order_Details.DeleteOnSubmit(oldDetail);SQLDELETE FROM [dbo].[Order Details]WHERE [OrderID] = 10422 AND [ProductID] = 26 AND ...
  • 20. Resources - LINQMSDN Developer Centerhttp://msdn2.microsoft.com/en-us/netframework/aa904594.aspxLINQ Forumhttp://forums.microsoft.com/msdn/showforum.aspx?forumid=123Channel9 Linq Videoshttp://channel9.msdn.com/tags/linqBlogsScott Guthrie http://weblogs.asp.net/scottgu/archive/2007/04/21/new-orcas-language-feature-query-syntax.aspxCharlie Calvert http://blogs.msdn.com/charlie/archive/2006/10/05/Links-to-LINQ.aspxLINQ HOLC# 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.