Click here to Skip to main content
15,889,863 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
how can we create Database looks like as follows in EntityFramework CodeFirst Appraoach:
Note:

I have created identity auto incremented by two and it is foreign key for all table.
How can we write FluentAPI for foreign Key and unique key?
SQL
Create Table [dbo].[UserAccount]
(
[UserID] int Identity(1,2),
[Email] nvarchar(50),
[UserName] nvarchar(50),
[Password]nvarchar(50),
Constraint [PkUserAccount] Primary Key([UserID]),
Constraint [UkEmail] Unique([Email]),
Constraint [UkUserName] Unique([UserName])
)
Go

Create Table dbo.UserPersonal
(
[UserID] int,
[Name] nvarchar(50),
[Nationality] nvarchar(50),
[Location] nvarchar(50),
[DoB]  date,
[Mobile] nvarchar(50),
[Gender] bit,
Constraint [PkUserPersonal] Primary Key([UserID]),
Constraint [FrUserIDPersonal] Foreign Key([UserID]) references dbo.[UserAccount]([UserID]) on delete cascade,
Constraint [UKMobile] Unique([Mobile])
)
Go

Create Table dbo.UserProfessional
(
[UserID] int,
[Experience] Int,
[Industry] nvarchar(50),
[FunctionalArea] nvarchar(50),
[KeySkills] nvarchar(50),
[Resume] nvarchar(50),
Constraint [PkUserProfessional] Primary Key([UserID]),
Constraint [FrUserIDProfessional] Foreign Key([UserID]) references dbo.[UserAccount]([UserID]) on delete cascade,
)
GO
Posted
Updated 17-Sep-13 1:29am
v2

1 solution

 
Share this answer
 
Comments
Member 10197079 17-Sep-13 7:36am    
Thanks for giving time
But these links are not related to Code first approach.
I am trying to create my database through model in mvc

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900