Click here to Skip to main content
12,243,383 members (39,455 online)
Click here to Skip to main content

Stats

41.9K views
2K downloads
86 bookmarked
Posted

LINQ FAQ: Part 2

, 28 Jul 2009 CPOL
This FAQ article is dedicated to LINQ to SQL.
LINQCrudWithEntities
LINQCrudWithEntities
App_Data
Sales.mdf
Sales_log.LDF
bin
LINQCrudWithEntities.dll
LINQtoSQLStoredProc.dll
LINQCrudWithEntities.csproj.user
obj
Debug
TempPE
Properties
LINQCrudWithEntities
App_Data
Sales.mdf
Sales_log.LDF
bin
LINQCrudWithEntities.dll
LINQtoSQLStoredProc.dll
LINQCrudWithEntities.csproj.user
obj
Debug
TempPE
Properties
LINQtoSQLStoredProc
LINQtoSQLStoredProc
App_Data
Sales.mdf
Sales_log.LDF
bin
LINQtoSQLStoredProc.dll
LINQtoSQLStoredProc.csproj.user
obj
Debug
TempPE
Properties
LINQtoSQL
SimpleLinqExample
App_Data
Sales.mdf
Sales_log.LDF
bin
SimpleLinqExample.dll
obj
Debug
TempPE
Properties
SimpleLinqExample.csproj.user
SimpleLinqExample.dll
SimpleLinqExample.csproj.user
SQL
��SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Customer]') AND type in (N'U'))

BEGIN

CREATE TABLE [dbo].[Customer](

	[CustomerId] [int] IDENTITY(1,1) NOT NULL,

	[CustomerCode] [nvarchar](50) NULL,

	[CustomerName] [nvarchar](50) NULL,

 CONSTRAINT [PK_Customer] PRIMARY KEY CLUSTERED 

(

	[CustomerId] ASC

)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

) ON [PRIMARY]

END

GO

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CustomerAddresses]') AND type in (N'U'))

BEGIN

CREATE TABLE [dbo].[CustomerAddresses](

	[Addressid] [int] IDENTITY(1,1) NOT NULL,

	[CustomerId] [int] NULL,

	[Address1] [nvarchar](50) NULL,

	[Address2] [nchar](10) NULL,

 CONSTRAINT [PK_CustomerAddresses] PRIMARY KEY CLUSTERED 

(

	[Addressid] ASC

)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

) ON [PRIMARY]

END

GO

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Phone]') AND type in (N'U'))

BEGIN

CREATE TABLE [dbo].[Phone](

	[PhoneId] [int] IDENTITY(1,1) NOT NULL,

	[AddressId] [int] NULL,

	[MobilePhone] [nvarchar](50) NULL,

	[LandLine] [nvarchar](50) NULL,

 CONSTRAINT [PK_Phone] PRIMARY KEY CLUSTERED 

(

	[PhoneId] ASC

)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

) ON [PRIMARY]

END

GO

IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_CustomerAddresses_Customer]') AND parent_object_id = OBJECT_ID(N'[dbo].[CustomerAddresses]'))

ALTER TABLE [dbo].[CustomerAddresses]  WITH CHECK ADD  CONSTRAINT [FK_CustomerAddresses_Customer] FOREIGN KEY([CustomerId])

REFERENCES [dbo].[Customer] ([CustomerId])

GO

IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Phone_CustomerAddresses]') AND parent_object_id = OBJECT_ID(N'[dbo].[Phone]'))

ALTER TABLE [dbo].[Phone]  WITH CHECK ADD  CONSTRAINT [FK_Phone_CustomerAddresses] FOREIGN KEY([AddressId])

REFERENCES [dbo].[CustomerAddresses] ([Addressid])

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author


You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160426.1 | Last Updated 29 Jul 2009
Article Copyright 2009 by Shivprasad koirala
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid