code first approach for connecting sql server 2008 with visual c# ,entity framework

23
Entity Framework Approach To Connect To MS SQL Server 2008 using Visual C# Following are the steps with Snapshots for connecting SQL Server and Visual C# Step 1: Create a Console Application: DB_School_Application1

Upload: kiran-kumar-talikoti

Post on 02-Jul-2015

1.161 views

Category:

Technology


0 download

DESCRIPTION

Hi,I am demonstrating how to connect to Database using Entity Framework Using Code First Approach

TRANSCRIPT

Page 1: Code First Approach For Connecting SQL Server 2008 With Visual C# ,Entity Framework

Entity Framework Approach To Connect To MS SQL Server 2008 using Visual C#

Following are the steps with Snapshots for connecting SQL Server and Visual C#

Step 1: Create a Console Application: DB_School_Application1

Page 2: Code First Approach For Connecting SQL Server 2008 With Visual C# ,Entity Framework

Entity Framework Approach To Connect To MS SQL Server 2008 using Visual C#

Step2: Right Click on DB_School_Application1 and a class called Student.

Page 3: Code First Approach For Connecting SQL Server 2008 With Visual C# ,Entity Framework

Entity Framework Approach To Connect To MS SQL Server 2008 using Visual C#

Step3: Add a Class Called Students to DB_School_Appliaction1 and its been Added here

Page 4: Code First Approach For Connecting SQL Server 2008 With Visual C# ,Entity Framework

Entity Framework Approach To Connect To MS SQL Server 2008 using Visual C#

Step4: Declare the variables Of Student Class and Set Properties and save

Page 5: Code First Approach For Connecting SQL Server 2008 With Visual C# ,Entity Framework

Entity Framework Approach To Connect To MS SQL Server 2008 using Visual C#

Step 5: Add a One More class Called Context

Page 6: Code First Approach For Connecting SQL Server 2008 With Visual C# ,Entity Framework

Entity Framework Approach To Connect To MS SQL Server 2008 using Visual C#

Step 6: Class Context has been successfully added to DB_School_Application1

Page 7: Code First Approach For Connecting SQL Server 2008 With Visual C# ,Entity Framework

Entity Framework Approach To Connect To MS SQL Server 2008 using Visual C#

Step 7: Right Click and Add a new Folder for Adding Framework DLL (Data Link Layer)

Page 8: Code First Approach For Connecting SQL Server 2008 With Visual C# ,Entity Framework

Entity Framework Approach To Connect To MS SQL Server 2008 using Visual C#

Step8: Rename the Folder Added as you want.

Page 9: Code First Approach For Connecting SQL Server 2008 With Visual C# ,Entity Framework

Entity Framework Approach To Connect To MS SQL Server 2008 using Visual C#

Step 9: Before Adding Framework save the application as shown.

Page 10: Code First Approach For Connecting SQL Server 2008 With Visual C# ,Entity Framework

Entity Framework Approach To Connect To MS SQL Server 2008 using Visual C#

Step 10: Right Click on the Program and select properties for copying address of Program’s

Page 11: Code First Approach For Connecting SQL Server 2008 With Visual C# ,Entity Framework

Entity Framework Approach To Connect To MS SQL Server 2008 using Visual C#

Step 11: In Property window right click and copy the address of programs for adding DLL framework.

Page 12: Code First Approach For Connecting SQL Server 2008 With Visual C# ,Entity Framework

Entity Framework Approach To Connect To MS SQL Server 2008 using Visual C#

Step12: After Copying Paste in C: Drive bar and locate the folder you added previously.

Page 13: Code First Approach For Connecting SQL Server 2008 With Visual C# ,Entity Framework

Entity Framework Approach To Connect To MS SQL Server 2008 using Visual C#

Step 13: Add the DLL Entity Framework to the Folder you created here its: Entity Framework lib

Page 14: Code First Approach For Connecting SQL Server 2008 With Visual C# ,Entity Framework

Entity Framework Approach To Connect To MS SQL Server 2008 using Visual C#

Step 14: Now right click on References and select Add References to browse the DLL Entity Framework

Page 15: Code First Approach For Connecting SQL Server 2008 With Visual C# ,Entity Framework

Entity Framework Approach To Connect To MS SQL Server 2008 using Visual C#

Step 15: Browse and Select then click Know DLL File has been added successfully.

Page 16: Code First Approach For Connecting SQL Server 2008 With Visual C# ,Entity Framework

Entity Framework Approach To Connect To MS SQL Server 2008 using Visual C#

Step16:

Now Entity Framework DLL is showing in Reference menu. In Context Class declare the Student Class

and set the properties as shown.

Page 17: Code First Approach For Connecting SQL Server 2008 With Visual C# ,Entity Framework

Entity Framework Approach To Connect To MS SQL Server 2008 using Visual C#

Step 17: Right Click on DB_School_Application1 and add select new Item option as shown for adding the

Application Configuration File.

Page 18: Code First Approach For Connecting SQL Server 2008 With Visual C# ,Entity Framework

Entity Framework Approach To Connect To MS SQL Server 2008 using Visual C#

Step18: Application Configuration file has been added successfully as shown.

Page 19: Code First Approach For Connecting SQL Server 2008 With Visual C# ,Entity Framework

Entity Framework Approach To Connect To MS SQL Server 2008 using Visual C#

Step 19: in App.Config File declare the DB path and Database name as shown.

Page 20: Code First Approach For Connecting SQL Server 2008 With Visual C# ,Entity Framework

Entity Framework Approach To Connect To MS SQL Server 2008 using Visual C#

Step20: In main programs file .Declare Object for Context and Student. Add the data to student object as

shown in fig.

Page 21: Code First Approach For Connecting SQL Server 2008 With Visual C# ,Entity Framework

Entity Framework Approach To Connect To MS SQL Server 2008 using Visual C#

Step 21: Now it is almost finished .Just press F5 to execute .Its showing that DB has been successfully

created in SQL server.

Page 22: Code First Approach For Connecting SQL Server 2008 With Visual C# ,Entity Framework

Entity Framework Approach To Connect To MS SQL Server 2008 using Visual C#

Step22: Now Login to SQL Server for viewing DB_School_Application.

Page 23: Code First Approach For Connecting SQL Server 2008 With Visual C# ,Entity Framework

Entity Framework Approach To Connect To MS SQL Server 2008 using Visual C#

Step 23: Yes Now in SQL Server DB School has been created successfully.

Thank You for your Patience,

Article By:

Kiran Kumar Talikoti.

SourceEdge Software Pvt Ltd