| This tutorial was created with Visual Studio .NET 2008, | | | | int Id { get; set; } |
| but can be recreated in 2005, after downloading and | | | | [Column(CanBeNull=true)]public string name { get; set; } |
| installing Microsoft's LINQ Community Technology | | | | [Column(CanBeNull=true)]public string city { get; set; |
| Preview release, which can be downloaded from here. | | | | }public people() |
| Visual Studio.NET 2008 makes it very easy for us to | | | | { |
| create LINQ to SQL Entities using the Object | | | | } |
| Relational Designer. What it does is creates classes | | | | } |
| and methods that relate to the database columns and | | | | It is advised to always include the table name in the |
| tables. This makes it possible for us to communicate | | | | class, although it is not really required if the class is |
| with the data using LINQ (Language Integrated Query). | | | | named the same as the table in the SQL database. |
| This tutorial will show how we can bypass the | | | | You should always declare the Primary Key, especially |
| Designer and write the class ourselves, so that we get | | | | if you are planning on making changes to the |
| a better understanding of what's going on. For this | | | | database. IsDbGenerated is also used where the |
| example, we will be using a SQL database with one | | | | database will auto-generate the values upon insert. |
| table and three columns - id, name, and city. | | | | In the class, we need to define a [Column] for each in |
| Once we have our database set up, we will create a | | | | the database table, and then the name of the column |
| new class to represent the database table structure. It | | | | should be represented by the public string (or int, etc.) |
| should look something like this:using System;using | | | | Next, we are going to display the data with a |
| System.Data.Linq.Mapping; | | | | GridView, and we will also add a textbox and button |
| [Table(Name="tblPeople")]public class people | | | | to the page to allow searching of the database. |
| { | | | | Our ASPX page will look something like this: |
| [Column(IsPrimaryKey=true, IsDbGenerated=true)]public | | | | For the full article please visit Happy Coding! |