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

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

 
The following is the procedure, with snapshots, for connecting to SQL Server and Visual C#.
 
Step 1: Create a Console Application: DB_School_Application1.
 
Entity-Framework-1.jpg
 
Step 2: Right-click on DB_School_Application1 and a class called Student.
 
Entity-Framework-2.jpg
 
Step 3: Add a class called Students to DB_School_Appliaction1 and it's been added here.
 
Entity-Framework-3.jpg
 
Step 4: Declare the variables of Student Class and Set Properties and save.
 
Entity-Framework-4.jpg
 
Step 5: Add one more class called Context.
 
Entity-Framework-5.jpg
 
Step 6: The class Context has been successfully added to DB_School_Application1.
 
Entity-Framework-6.jpg
 
Step 7: Right-click and add a new folder for adding the Framework DLL (Dynamic Link Library).
 
Entity-Framework-7.jpg
 
Step 8: Rename the folder Added as you want.
 
Entity-Framework-8.jpg
 
Step 9: Before adding the Framework save the application as shown.
 
Entity-Framework-9.jpg
 
Step 10: Right-click on the Program.cs file and select properties for copying the address of the Program's something.
 
Entity-Framework-10.jpg
 
Step 11: In the Properties window right-click and copy the address of the programs for adding the DLL framework.
 
Entity-Framework-11.jpg
 
Step 12: After copying, paste into the C: Drive bar and locate the folder you added previously.
 
Entity-Framework-12.jpg
 
Step 13: Add the DLL Entity Framework to the folder you created, here it is: Entity Framework lib
 
Entity-Framework-13.jpg
 
Step 14: Now right-click on References and select Add References to browse to the DLL Entity Framework
 
Entity-Framework-14.jpg
 
Step 15: Browse and Select then click Know DLL File has been added successfully.
 
Entity-Framework-15.jpg
 
Step 16: Now the Entity Framework DLL is showing in the References menu. In the Context Class declare the Student Class and set the properties as shown.
 
Entity-Framework-16.jpg
 
Step 17: Right-click on DB_School_Application1 and select "New Item..." | "Add" as shown for adding the Application Configuration File.
 
Entity-Framework-17.jpg
 
Step 18: The Application Configuration file has been added successfully as shown.
 
Entity-Framework-18.jpg
 
Step 19: In the App.Config File, declare the DB path and Database name as shown.
 
Entity-Framework-19.jpg
 
Step 20: In the main programs file, declare Context and Student objects. Add the data to the Student object as shown in the figure.
 
Entity-Framework-20.jpg
 
Step 21: Now it is almost finished. Just press F5 to execute. It will show that the DB has been successfully created in SQL Server.
 
Entity-Framework-21.jpg
 
Step 22: Now login to SQL Server to view DB_School_Application.
 
Entity-Framework-22.jpg
 
Step 23: Yes, now in SQL Server, DB School has been created successfully.
 
Entity-Framework-23.jpg