code first approach for connecting sql server 2008 with visual c# ,entity framework
DESCRIPTION
Hi,I am demonstrating how to connect to Database using Entity Framework Using Code First ApproachTRANSCRIPT
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
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.
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
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
Entity Framework Approach To Connect To MS SQL Server 2008 using Visual C#
Step 5: Add a One More class Called Context
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
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)
Entity Framework Approach To Connect To MS SQL Server 2008 using Visual C#
Step8: Rename the Folder Added as you want.
Entity Framework Approach To Connect To MS SQL Server 2008 using Visual C#
Step 9: Before Adding Framework save the application as shown.
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
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.
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.
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
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
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.
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.
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.
Entity Framework Approach To Connect To MS SQL Server 2008 using Visual C#
Step18: Application Configuration file has been added successfully as shown.
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.
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.
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.
Entity Framework Approach To Connect To MS SQL Server 2008 using Visual C#
Step22: Now Login to SQL Server for viewing DB_School_Application.
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