Part 1 LINQ to SQL HD

04.09.2014
Text version of the video http://csharp-video-tutorials.blogspot.com/2014/09/part-1-linq-to-sql.html Slides http://csharp-video-tutorials.blogspot.com/2014/09/part-1-linq-to-sql_3.html LINQ to SQL Tutorial - All Text Articles & Slides http://csharp-video-tutorials.blogspot.com/2014/09/linq-to-sql-tutorial.html LINQ to SQL Tutorial Playlist https://www.youtube.com/playlist?list=PL6n9fhu94yhXCHPed2Q9oBkgvzw9Re8hC Dot Net, SQL, Angular, JavaScript, jQuery and Bootstrap complete courses https://www.youtube.com/user/kudvenkat/playlists?view=1&sort=dd In this video we will discuss using LINQ to SQL to retrieve data from a SQL Server database. What is LINQ to SQL LINQ to SQL is an ORM (Object Relational Mapping) framework, that automatically creates strongly typed .net classes based on database tables. We can then write LINQ to SQL queries (Select, Insert, Update, Delete) in any .NET supported language (C#, VB etc). The LINQ to SQL provider will then convert LINQ queries to Transact-SQL that the SQL Server database understands. LINQ to SQL supports transactions, views, and stored procedures. LINQ to SQL supports only SQL Server database. Since LINQ to SQL models a relational database using strongly typed .net classes, we have the following advantages 1. Intellisense support 2. Compile time error checking 3. Debugging support Modeling Databases - Creating LINQ to SQL classes Use the LINQ to SQL designer that ships with Visual Studio to create LINQ to SQL classes. Here are the steps. Step 1 : Create a dataabse. Name it Sample. Step 2 : Create Departments and Employees tables and populate them with test data. Step 3 : Run Visual Studio as an administrator. Create a new empty asp.net web application project. Name it Demo. Step 4 : Right click on the project in solution explorer and add LINQ to SQL Classes. Change the name from DataClasses1.dbml to Sample.dbml Step 5 : At this point, Sample.dbml file should have been added to the project. Click on Server Explorer link on Sample.dbml file. In the Server Explorer window, you should find all the tables in the Sample database. Drag and drop the tables on Sample.dbml file. Step 6: At this point we should have Department and Employee classes. The properties of the class map to the columns of the respective table in the database. The arrow between the classes represent the association between them. These associations are modeled based on the primary-key/foreign-key relationships between the tables in the database. Notice that the arrow is pointing from Department to Employee entity. In this case there is a One-to-Many relationship between Department and Employee entities. A Department can have 1 or more employees. Step 7 : Add a WebForm to the project. Drag and Drop a GridView control on the webform. Step 8 : Copy and paste the following code in the code-behind file. using System; using System.Linq; namespace Demo { public partial class WebForm1 : System.Web.UI.Page { protected voi

Похожие видео

Показать еще