Create an Entity Data Model (EF basic Series 5) and an entity ef
Now I want to create an object data model for the database (SchoolDB) given at the end of the above section;
The script for the SchoolDB database has been written as follows:
USE masterGO if exists (SELECT * FROM sys. sysdatabases WHERE name = 'schooldb') drop database SchoolDB; go create database SchoolDBGO USE SchoolDB; GO -- CREATE Standard table if exists (SELECT * FROM sysobjects WHERE name = 'standard ') drop table [Standard]; go create table [Standard] (StandardID int primary key, StandardName NVARCHAR (50), [Description] NVARCHAR (250 )); GO -- CREATE a Student table if exists (SELECT * FROM sysobjects WHERE name = 'student ') drop table Student; go create table Student (StudentID int primary key, StudentName NVARCHAR (100) not null, StandardID int references [Standard] (StandardID), [RowVersion] NVARCHAR (50 )); GO -- CREATE StudentAddress table if exists (SELECT * FROM sysobjects WHERE name = 'studentaddress') drop table StudentAddress; go create table StudentAddress (StudentID int primary key, Address1 NVARCHAR (100 ), address2 NVARCHAR (100), City NVARCHAR (100), [State] NVARCHAR (100), CONSTRAINT StudentID_FK foreign key (StudentID) REFERENCES dbo. student (StudentID); GO -- CREATE a Teacher table if exists (SELECT * FROM sysobjects WHERE name = 'teacher') drop table Teacher; go create table Teacher (TeacherID int primary key, teacherName NVARCHAR (50), StandardID int references [Standard] (StandardID), TeacherType NVARCHAR (100 )); GO -- CREATE Course table if exists (SELECT * FROM sysobjects WHERE name = 'Course') drop table Course; go create table Course (CourseID int primary key, CourseName NVARCHAR (50 ), location NVARCHAR (500), TeacherID int references dbo. teacher (TeacherID); GO -- create the StudentCourse table if exists (SELECT * FROM sysobjects WHERE name = 'studentcourse') drop table StudentCourse; go create table StudentCourse (StudentID int references Student (StudentID), CourseID int references dbo. course (CourseID), CONSTRAINT StudentID_CourseID primary key (StudentID, CourseID),); GO
First, open the project created in the previous section, select "project name", right-click and select "attribute", and make sure that the. NET framework version used is 4.5;
Next, create an object data model: select the Project name:
Now let's open the EDMX file using the XML Compiler: