SlideShare a Scribd company logo
1
Creating Primary Key And Foreign Key Association in SQL Server 2008 Using
Visual C# 2010 and Entity Framework 5.0
Date:25.06.2013
Hi,
In this article I am showing how to create primary key and foreign key association in Employee
and Department table .I have taken Dept_Id as the foreign key in Employee table .In my previous article
I have shown how to add Entity Frame work to visual C# please check it once before going through this
article .Here I am directly showing creation of primary key and foreign key association .You can
download Entity Framework.dll file from net and add it to Visual C#. The following are the steps to
create association between foreign key and primary key
Step 1: First create a console application and add it .Here I have named FK_PK_Association_Application.
2
Creating Primary Key And Foreign Key Association in SQL Server 2008 Using
Visual C# 2010 and Entity Framework 5.0
Date:25.06.2013
Step 2: Now add a Department table.
3
Creating Primary Key And Foreign Key Association in SQL Server 2008 Using
Visual C# 2010 and Entity Framework 5.0
Date:25.06.2013
Step 3: Declare variable and set the properties for Department Table.
4
Creating Primary Key And Foreign Key Association in SQL Server 2008 Using
Visual C# 2010 and Entity Framework 5.0
Date:25.06.2013
Step 4: Add Employee Table.
5
Creating Primary Key And Foreign Key Association in SQL Server 2008 Using
Visual C# 2010 and Entity Framework 5.0
Date:25.06.2013
Step 5: Declare variables of Employee Table and Set the properties .Also Declare Department Table as
Virtual.
6
Creating Primary Key And Foreign Key Association in SQL Server 2008 Using
Visual C# 2010 and Entity Framework 5.0
Date:25.06.2013
Step 6: Add Entity Frame Work To FK_PK_Console Application. Add a reference to it as shown in
previous article named “Entity Framework Approach to Connect to MS SQL Server and Visual C#”.
7
Creating Primary Key And Foreign Key Association in SQL Server 2008 Using
Visual C# 2010 and Entity Framework 5.0
Date:25.06.2013
Step 7: Add Context Class as shown.
8
Creating Primary Key And Foreign Key Association in SQL Server 2008 Using
Visual C# 2010 and Entity Framework 5.0
Date:25.06.2013
Step 8: Now set the properties for Employee and Department Class in Context Class.
9
Creating Primary Key And Foreign Key Association in SQL Server 2008 Using
Visual C# 2010 and Entity Framework 5.0
Date:25.06.2013
Step 9: Add Application Configuration File.
10
Creating Primary Key And Foreign Key Association in SQL Server 2008 Using
Visual C# 2010 and Entity Framework 5.0
Date:25.06.2013
Step 10: Now declare the catalog or Database name and data source path of your SQL Server using
Connection string.
11
Creating Primary Key And Foreign Key Association in SQL Server 2008 Using
Visual C# 2010 and Entity Framework 5.0
Date:25.06.2013
Step 11:
Create Object for Context Class, Employee Class, and Department Class and Initialize the
Database .A database initializer is a class that takes care of database creation and initialization
in a Code First application. It is the job of database initializer to create the database and
required tables based on the data model classes you create .Finally Add Employee Object to
Context.
12
Creating Primary Key And Foreign Key Association in SQL Server 2008 Using
Visual C# 2010 and Entity Framework 5.0
Date:25.06.2013
Step 12: Press F5.Its Showing that DB has created successfully!!
13
Creating Primary Key And Foreign Key Association in SQL Server 2008 Using
Visual C# 2010 and Entity Framework 5.0
Date:25.06.2013
Step 13: Login into SQL Server and Check .Finally Database named FK_PK_Association has been created
As shown in fig.
Thank You for Your Patience,
Article By:
Kiran Kumar Talikoti
Source Edge Software Pvt Ltd.

More Related Content

Similar to Code First Approach Of Creating Primary Key And Foreign Key Association In SQL Server 2008 Using Visual C# ,Entity Framework

SharePoint 2010 authentications
SharePoint 2010 authenticationsSharePoint 2010 authentications
SharePoint 2010 authentications
Wyngate Solutions
 
ASP.NET Identity
ASP.NET IdentityASP.NET Identity
ASP.NET Identity
Suzanne Simmons
 
ASP.NET Core MVC with EF Core code first
ASP.NET Core MVC with EF Core code firstASP.NET Core MVC with EF Core code first
ASP.NET Core MVC with EF Core code first
Md. Aftab Uddin Kajal
 
Overview of CSharp MVC3 and EF4
Overview of CSharp MVC3 and EF4Overview of CSharp MVC3 and EF4
Overview of CSharp MVC3 and EF4
Rich Helton
 
Labs And Walkthroughs
Labs And WalkthroughsLabs And Walkthroughs
Labs And Walkthroughs
Bryan Tuttle
 
AspMVC4 start101
AspMVC4 start101AspMVC4 start101
AspMVC4 start101
Rich Helton
 
Darian Lowe Portfolio
Darian Lowe PortfolioDarian Lowe Portfolio
Darian Lowe Portfoliodarian.lowe
 
ASP.NET MVC 5 Building Your First Web Application (A Beginner S Guide
ASP.NET MVC 5  Building Your First Web Application (A Beginner S GuideASP.NET MVC 5  Building Your First Web Application (A Beginner S Guide
ASP.NET MVC 5 Building Your First Web Application (A Beginner S Guide
Alicia Buske
 
Enterprise Level Application Architecture with Web APIs using Entity Framewor...
Enterprise Level Application Architecture with Web APIs using Entity Framewor...Enterprise Level Application Architecture with Web APIs using Entity Framewor...
Enterprise Level Application Architecture with Web APIs using Entity Framewor...
Akhil Mittal
 
Bindu dot net_cv
Bindu dot net_cvBindu dot net_cv
Bindu dot net_cv
Himabindu Gurajala
 
Oracle endeca information discovery v3.0 integration with the obiee 11g bi se...
Oracle endeca information discovery v3.0 integration with the obiee 11g bi se...Oracle endeca information discovery v3.0 integration with the obiee 11g bi se...
Oracle endeca information discovery v3.0 integration with the obiee 11g bi se...
Ravi Kumar Lanke
 
Murach : How to develop a single-page MVC web
Murach : How to develop a single-page MVC web Murach : How to develop a single-page MVC web
Murach : How to develop a single-page MVC web
MahmoudOHassouna
 
Acquia Drupal Certification
Acquia Drupal CertificationAcquia Drupal Certification
Acquia Drupal Certification
Philip Norton
 
Microsoft MCSD 70-499 it-exams.fr
Microsoft MCSD 70-499 it-exams.frMicrosoft MCSD 70-499 it-exams.fr
Microsoft MCSD 70-499 it-exams.fr
lilylucy
 
Sql Saturday 228 Rapid Data Integration Using SharePoint BCS
Sql Saturday 228   Rapid Data Integration Using SharePoint BCSSql Saturday 228   Rapid Data Integration Using SharePoint BCS
Sql Saturday 228 Rapid Data Integration Using SharePoint BCSObilogic
 
Cis407 a ilab 6 web application development devry university
Cis407 a ilab 6 web application development devry universityCis407 a ilab 6 web application development devry university
Cis407 a ilab 6 web application development devry universitylhkslkdh89009
 
4) databases
4) databases4) databases
4) databasestechbed
 
07 asp.net session10
07 asp.net session1007 asp.net session10
07 asp.net session10Mani Chaubey
 
Entity Framework Code First Migrations
Entity Framework Code First MigrationsEntity Framework Code First Migrations
Entity Framework Code First Migrations
Diluka99999
 

Similar to Code First Approach Of Creating Primary Key And Foreign Key Association In SQL Server 2008 Using Visual C# ,Entity Framework (20)

SharePoint 2010 authentications
SharePoint 2010 authenticationsSharePoint 2010 authentications
SharePoint 2010 authentications
 
ASP.NET Identity
ASP.NET IdentityASP.NET Identity
ASP.NET Identity
 
ASP.NET Core MVC with EF Core code first
ASP.NET Core MVC with EF Core code firstASP.NET Core MVC with EF Core code first
ASP.NET Core MVC with EF Core code first
 
Overview of CSharp MVC3 and EF4
Overview of CSharp MVC3 and EF4Overview of CSharp MVC3 and EF4
Overview of CSharp MVC3 and EF4
 
Labs And Walkthroughs
Labs And WalkthroughsLabs And Walkthroughs
Labs And Walkthroughs
 
AspMVC4 start101
AspMVC4 start101AspMVC4 start101
AspMVC4 start101
 
Asp net-mvc-3 tier
Asp net-mvc-3 tierAsp net-mvc-3 tier
Asp net-mvc-3 tier
 
Darian Lowe Portfolio
Darian Lowe PortfolioDarian Lowe Portfolio
Darian Lowe Portfolio
 
ASP.NET MVC 5 Building Your First Web Application (A Beginner S Guide
ASP.NET MVC 5  Building Your First Web Application (A Beginner S GuideASP.NET MVC 5  Building Your First Web Application (A Beginner S Guide
ASP.NET MVC 5 Building Your First Web Application (A Beginner S Guide
 
Enterprise Level Application Architecture with Web APIs using Entity Framewor...
Enterprise Level Application Architecture with Web APIs using Entity Framewor...Enterprise Level Application Architecture with Web APIs using Entity Framewor...
Enterprise Level Application Architecture with Web APIs using Entity Framewor...
 
Bindu dot net_cv
Bindu dot net_cvBindu dot net_cv
Bindu dot net_cv
 
Oracle endeca information discovery v3.0 integration with the obiee 11g bi se...
Oracle endeca information discovery v3.0 integration with the obiee 11g bi se...Oracle endeca information discovery v3.0 integration with the obiee 11g bi se...
Oracle endeca information discovery v3.0 integration with the obiee 11g bi se...
 
Murach : How to develop a single-page MVC web
Murach : How to develop a single-page MVC web Murach : How to develop a single-page MVC web
Murach : How to develop a single-page MVC web
 
Acquia Drupal Certification
Acquia Drupal CertificationAcquia Drupal Certification
Acquia Drupal Certification
 
Microsoft MCSD 70-499 it-exams.fr
Microsoft MCSD 70-499 it-exams.frMicrosoft MCSD 70-499 it-exams.fr
Microsoft MCSD 70-499 it-exams.fr
 
Sql Saturday 228 Rapid Data Integration Using SharePoint BCS
Sql Saturday 228   Rapid Data Integration Using SharePoint BCSSql Saturday 228   Rapid Data Integration Using SharePoint BCS
Sql Saturday 228 Rapid Data Integration Using SharePoint BCS
 
Cis407 a ilab 6 web application development devry university
Cis407 a ilab 6 web application development devry universityCis407 a ilab 6 web application development devry university
Cis407 a ilab 6 web application development devry university
 
4) databases
4) databases4) databases
4) databases
 
07 asp.net session10
07 asp.net session1007 asp.net session10
07 asp.net session10
 
Entity Framework Code First Migrations
Entity Framework Code First MigrationsEntity Framework Code First Migrations
Entity Framework Code First Migrations
 

Recently uploaded

FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 

Code First Approach Of Creating Primary Key And Foreign Key Association In SQL Server 2008 Using Visual C# ,Entity Framework

  • 1. 1 Creating Primary Key And Foreign Key Association in SQL Server 2008 Using Visual C# 2010 and Entity Framework 5.0 Date:25.06.2013 Hi, In this article I am showing how to create primary key and foreign key association in Employee and Department table .I have taken Dept_Id as the foreign key in Employee table .In my previous article I have shown how to add Entity Frame work to visual C# please check it once before going through this article .Here I am directly showing creation of primary key and foreign key association .You can download Entity Framework.dll file from net and add it to Visual C#. The following are the steps to create association between foreign key and primary key Step 1: First create a console application and add it .Here I have named FK_PK_Association_Application.
  • 2. 2 Creating Primary Key And Foreign Key Association in SQL Server 2008 Using Visual C# 2010 and Entity Framework 5.0 Date:25.06.2013 Step 2: Now add a Department table.
  • 3. 3 Creating Primary Key And Foreign Key Association in SQL Server 2008 Using Visual C# 2010 and Entity Framework 5.0 Date:25.06.2013 Step 3: Declare variable and set the properties for Department Table.
  • 4. 4 Creating Primary Key And Foreign Key Association in SQL Server 2008 Using Visual C# 2010 and Entity Framework 5.0 Date:25.06.2013 Step 4: Add Employee Table.
  • 5. 5 Creating Primary Key And Foreign Key Association in SQL Server 2008 Using Visual C# 2010 and Entity Framework 5.0 Date:25.06.2013 Step 5: Declare variables of Employee Table and Set the properties .Also Declare Department Table as Virtual.
  • 6. 6 Creating Primary Key And Foreign Key Association in SQL Server 2008 Using Visual C# 2010 and Entity Framework 5.0 Date:25.06.2013 Step 6: Add Entity Frame Work To FK_PK_Console Application. Add a reference to it as shown in previous article named “Entity Framework Approach to Connect to MS SQL Server and Visual C#”.
  • 7. 7 Creating Primary Key And Foreign Key Association in SQL Server 2008 Using Visual C# 2010 and Entity Framework 5.0 Date:25.06.2013 Step 7: Add Context Class as shown.
  • 8. 8 Creating Primary Key And Foreign Key Association in SQL Server 2008 Using Visual C# 2010 and Entity Framework 5.0 Date:25.06.2013 Step 8: Now set the properties for Employee and Department Class in Context Class.
  • 9. 9 Creating Primary Key And Foreign Key Association in SQL Server 2008 Using Visual C# 2010 and Entity Framework 5.0 Date:25.06.2013 Step 9: Add Application Configuration File.
  • 10. 10 Creating Primary Key And Foreign Key Association in SQL Server 2008 Using Visual C# 2010 and Entity Framework 5.0 Date:25.06.2013 Step 10: Now declare the catalog or Database name and data source path of your SQL Server using Connection string.
  • 11. 11 Creating Primary Key And Foreign Key Association in SQL Server 2008 Using Visual C# 2010 and Entity Framework 5.0 Date:25.06.2013 Step 11: Create Object for Context Class, Employee Class, and Department Class and Initialize the Database .A database initializer is a class that takes care of database creation and initialization in a Code First application. It is the job of database initializer to create the database and required tables based on the data model classes you create .Finally Add Employee Object to Context.
  • 12. 12 Creating Primary Key And Foreign Key Association in SQL Server 2008 Using Visual C# 2010 and Entity Framework 5.0 Date:25.06.2013 Step 12: Press F5.Its Showing that DB has created successfully!!
  • 13. 13 Creating Primary Key And Foreign Key Association in SQL Server 2008 Using Visual C# 2010 and Entity Framework 5.0 Date:25.06.2013 Step 13: Login into SQL Server and Check .Finally Database named FK_PK_Association has been created As shown in fig. Thank You for Your Patience, Article By: Kiran Kumar Talikoti Source Edge Software Pvt Ltd.