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
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'