Creating Linq to Sql Entities in C#

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 andIt is advised to always include the table name in the
tables. This makes it possible for us to communicateclass, 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 theYou should always declare the Primary Key, especially
Designer and write the class ourselves, so that we getif you are planning on making changes to the
a better understanding of what's going on. For thisdatabase. IsDbGenerated is also used where the
example, we will be using a SQL database with onedatabase 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 athe database table, and then the name of the column
new class to represent the database table structure. Itshould be represented by the public string (or int, etc.)
should look something like this:using System;usingNext, 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 peopleto the page to allow searching of the database.
{Our ASPX page will look something like this:
[Column(IsPrimaryKey=true, IsDbGenerated=true)]publicFor the full article please visit Happy Coding!