LINQ - Tutorial LINQ To SQL - Part 1 (CodeGod - de Backup)
LINQ - Tutorial LINQ To SQL - Part 1 (CodeGod - de Backup)
NET Chat
Tutorial LINQ to SQL - Part 1 Section: Database serial submitted this resource Visit the profile here Rating: Not rated yet!
Introduction
This article is the first in series, to get closer with LINQ to SQL. Maybe you ask, what is the based language LINQ?
What is LINQ?
LINQ is the abbreviation for Language Integrated Query and it's developed by Microsoft. The goal of LINQ is to directly involve SQL, XLink and XQuery queries in a programming language like C# or VB.net. The advantage of LINQ is that the compiler can check the code for errors or to optimize it.
The syntax is similar to SQL like "select", "from" and "where". Ok, and is LINQ to SQL something special? - LINQ to SQL is a kind of O/R-Mapper, and how it works I will show you in this and the following articles.
Figure 1 In the designer there are four classes designed (INHO the most used tables from northwind around the world?): Product, Category, Order and OrderDetail. Each property of a class represents a column in the table and an instance of a class represesents a row in the database. The arrows and lines are like UML and shows relationships. The right window shows stored procedures wich interacts with our database.
Figure 2 So, the database is modelled and our classes are created, and now? Let's show some code-examples for working with all these classes.
MAY Clo He
2008
2010
2011
product =
Then we change some details of the product and save the changes in the database.
NorthwindDataContext nwContext = new NorthwindDataContext(); Product product = nwContext.Products.Single( prod => prod.ProductName == "Toy 1"); product.UnitPrice = 100; product.UnitsInStock = 10; nwContext.SubmitChagnes();
Product product2 = new Product(); product1.ProductName = "Thing 1"; product2.ProductName = "Thing2"; category.Products.Add(product1); category.Products.Add(product2); nwContext.Categories.Add(category); nwContext.SubmitChanges();
And now we just delete some products from the database the same way as before.
NorthwindDataContext nwContext = new NorthwindDataContext(); var products = from product in nwContext.Products where product.ProductName.Contains("Toy") select product; nwContext.Products.RemoveAll(products); nwContext.SubmitChanges();
You see, LINQ to SQL is an easy way to work with databases. I hope this introduction helps you to work with LtSQL. The next articles go deeper into some details, so stay tuned.
Reader-Comments:
Impressum | AGB | Datenschutzerklrung Top-Handy-Bundles | Anzeigen Web | Kostenlose Kleinanzeigen | Kleinanzeigen-Riese anzeigen-kostenlos.com | Singlebrse kostenlos | Suchmaschinenoptimierung | Plastikkarten Drucker | Firmen aus Bayern Website-Work | Fehlsichtigkeit | dotnet-forum | .NET BlogBook | Schufa | SEO | Place my ad here...