TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
vishal patil
NA
7
5.8k
How to Create Foreign key ??
Feb 1 2015 2:48 AM
I am using code first approach to create database.
Then i am try to Update Database in Package console Manger using
Update-Database -Verbose command error show :-
The navigation property 'UserId' is not a declared property on type 'User'. Verify that it has not been explicitly excluded from the model and that it is a valid navigation property.
[Table("UserProfile")]
public class UserProfile
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
public string UserName { get; set; }
public virtual ICollection<User> Usera { get; set; }
}
public class User
{
[Key]
public long u_ID { get; set; }
//public int UserId { get; set; }
[Required(ErrorMessage = "Please Enter Headline name ")]
[Display(Name = "Headline Profile")]
public string head_profile { get; set; }
[Required(ErrorMessage = "Please Enter Full Name")]
[Display(Name = "Full Name:")]
public string full_name { get; set; }
[ForeignKey("UserId")]
public int UserId { get; set; }
public virtual UserProfile UserProfilefk { get; set; }
}
How to Create Foreign key
Reply
Answers (
1
)
layer
how to get data from 2 tables