Click here to Skip to main content
15,896,201 members
Articles / Desktop Programming / WPF

Building WPF Applications with Self-Tracking Entity Generator - Project Setup

Rate me:
Please Sign up or sign in to vote.
4.80/5 (11 votes)
20 Feb 2012CPOL10 min read 75.8K   4.8K   54  
This article describes the project setup of building a WPF sample application with Self-Tracking Entity Generator for WPF/Silverlight.
��SET NOCOUNT ON

GO



USE master

GO

if exists (select * from sysdatabases where name='SCHOOL')

        drop database SCHOOL

GO



DECLARE @device_directory NVARCHAR(520)

SELECT @device_directory = SUBSTRING(filename, 1, CHARINDEX(N'master.mdf', LOWER(filename)) - 1)

FROM master.dbo.sysaltfiles WHERE dbid = 1 AND fileid = 1



EXECUTE (N'CREATE DATABASE SCHOOL

  ON PRIMARY (NAME = N''SCHOOL'', FILENAME = N''' + @device_directory + N'SCHOOL.mdf'')

  LOG ON (NAME = N''SCHOOL_log'',  FILENAME = N''' + @device_directory + N'SCHOOL.ldf'')')

GO



exec sp_dboption 'SCHOOL','trunc. log on chkpt.','true'

exec sp_dboption 'SCHOOL','select into/bulkcopy','true'

GO



set quoted_identifier on

GO



/* Set DATEFORMAT so that the date strings are interpreted correctly regardless of

   the default DATEFORMAT on the server.

*/

SET DATEFORMAT mdy

GO

USE [SCHOOL]

GO

if  exists (select * from sys.objects where object_id = object_id(N'[dbo].[Enrollment]') and type in (N'U'))

    drop table [dbo].[Enrollment]

GO

if  exists (select * from sys.objects where object_id = object_id(N'[dbo].[Course]') and type in (N'U'))

    drop table [dbo].[Course]

GO

if  exists (select * from sys.objects where object_id = object_id(N'[dbo].[Person]') and type in (N'U'))

    drop table [dbo].[Person]

GO



USE [SCHOOL]

GO

/****** Object:  Table [dbo].[Person]  ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

SET ANSI_PADDING ON

GO

CREATE TABLE [dbo].[Person](

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

    [Name] [varchar](50) NOT NULL,

    [EnrollmentDate] [datetime] NULL,

    [HireDate] [datetime] NULL,

    [Salary] [decimal](18, 2) NULL,

    [Role] [varchar](50) NOT NULL,

    [Version] [timestamp] NOT NULL,

 CONSTRAINT [PK_Person] PRIMARY KEY CLUSTERED 

(

    [PersonId] ASC

)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]

) ON [PRIMARY]

GO

SET ANSI_PADDING OFF

GO

/****** Object:  Table [dbo].[Course]  ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

SET ANSI_PADDING ON

GO

CREATE TABLE [dbo].[Course](

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

    [InstructorId] [int] NOT NULL,

    [Title] [varchar](50) NOT NULL,

    [Version] [timestamp] NOT NULL,

 CONSTRAINT [PK_Course] PRIMARY KEY CLUSTERED 

(

    [CourseId] ASC

)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]

) ON [PRIMARY]

GO

SET ANSI_PADDING OFF

GO

/****** Object:  Table [dbo].[Enrollment]  ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE TABLE [dbo].[Enrollment](

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

    [StudentId] [int] NOT NULL,

    [CourseId] [int] NOT NULL,

    [Paid] [bit] NOT NULL,

    [Version] [timestamp] NOT NULL,

 CONSTRAINT [PK_Enrollment] PRIMARY KEY CLUSTERED 

(

    [EnrollmentId] ASC

)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]

) ON [PRIMARY]

GO

/****** Object:  ForeignKey [FK_Course_Instructor]  ******/

ALTER TABLE [dbo].[Course]  WITH CHECK ADD  CONSTRAINT [FK_Course_Instructor] FOREIGN KEY([InstructorId])

REFERENCES [dbo].[Person] ([PersonId])

GO

ALTER TABLE [dbo].[Course] CHECK CONSTRAINT [FK_Course_Instructor]

GO

/****** Object:  ForeignKey [FK_Enrollment_Course]  ******/

ALTER TABLE [dbo].[Enrollment]  WITH CHECK ADD  CONSTRAINT [FK_Enrollment_Course] FOREIGN KEY([CourseId])

REFERENCES [dbo].[Course] ([CourseId])

GO

ALTER TABLE [dbo].[Enrollment] CHECK CONSTRAINT [FK_Enrollment_Course]

GO

/****** Object:  ForeignKey [FK_Enrollment_Student]  ******/

ALTER TABLE [dbo].[Enrollment]  WITH CHECK ADD  CONSTRAINT [FK_Enrollment_Student] FOREIGN KEY([StudentId])

REFERENCES [dbo].[Person] ([PersonId])

GO

ALTER TABLE [dbo].[Enrollment] CHECK CONSTRAINT [FK_Enrollment_Student]

GO

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)


Written By
Software Developer (Senior)
United States United States
Weidong has been an information system professional since 1990. He has a Master's degree in Computer Science, and is currently a MCSD .NET

Comments and Discussions