ASP Web Hosting | Windows Hosting Technology News

Creating LINQ to SQL 2008 Entities in C#

Posted on: July 20, 2009

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 tables. This makes it possible for us to communicate with the data using LINQ (Language Integrated Query).

For this example, we will be using a SQL 2008 database with one table and three columns – id, name, and city.
Once we have our database set up, we will create a new class to represent the database table structure. It should look something like this:

using System;
using System.Data.Linq.Mapping;

[Table(Name=”tblPeople”)]
public class people
{
[Column(IsPrimaryKey=true, IsDbGenerated=true)]
public int Id { get; set; }

[Column(CanBeNull=true)]
public string name { get; set; }

[Column(CanBeNull=true)]
public string city { get; set; }

public people()
{

}
}

It is advised to always include the table name in the class, although it is not really required if the class is named the same as the table in the SQL database.
Register the ASP.NET hosting plan with the latest SQL Server 2008 hosting from SeekDotNet.com and receive reliable supports on the web hosting plan.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Web Hosting Categories

Top Clicks

  • None
July 2009
M T W T F S S
« Jun   Aug »
 12345
6789101112
13141516171819
20212223242526
2728293031  
%d bloggers like this: