I do the same thing that yorrick showed in your example, the difference is that I do not use the list Employe But a table in a database. Now my problem is how to use the ForeignKey with AccountModel. If I write the property as I did above, visual studio
gives me error.
[ForeignKey("UserId")]
public virtual AccountModel AccountModel { get; set; }
Now
I couldmake the associationbetween the tables,I had to usecode like this:D
[ForeignKey("UserId")]
public virtual MembershipUser User
{
get
{
return Membership.GetUser(UserId);
}
}
Now
I have tomake surethat when I createa newemploye
there is adropdownlistwhere I canchoose thename of the user,inmy controller
Itriedto
implelemtaresimilar codebut stilldoes not work :/
ViewBag.User = new SelectList(Membership.GetUser());
PSI am usingEntity
Frameworkcodefirst
for theemployee tableanddefaultmembership
for myusers ;)
Mirko Pastor...
Member
104 Points
93 Posts
Re: Display a specific data for User
Feb 22, 2012 11:45 AM|LINK
I do the same thing that yorrick showed in your example, the difference is that I do not use the list Employe But a table in a database. Now my problem is how to use the ForeignKey with AccountModel. If I write the property as I did above, visual studio gives me error.
[ForeignKey("UserId")] public virtual AccountModel AccountModel { get; set; }Mirko Pastor...
Member
104 Points
93 Posts
Re: Display a specific data for User
Feb 22, 2012 02:26 PM|LINK
Now I could make the association between the tables, I had to use code like this: D
[ForeignKey("UserId")] public virtual MembershipUser User { get { return Membership.GetUser(UserId); } }Now I have to make sure that when I create a new employe there is a dropdownlist where I can choose the name of the user, in my controller I tried to implelemtare similar code but still does not work :/
ViewBag.User = new SelectList(Membership.GetUser());
PS I am using Entity Framework code first for the employee table and default membership for my users ;)