none
Relationship between asp.net default User table and my code first class? RRS feed

  • Question

  • I have a class Customer. I want to do relationship between ASP.NET default User table.(One-to-one). My class is:

    public class Customer
    {
        [Key]
        public int customer_id { get; set; }
        public string customer_name{ get; set; }
        //this is foreing key that refer to User table that is generated by Asp.Net
        public string user_id
    
        public virtual User User{ get; set; }
    }

    How can I do this. I m new about code first development.

    Thanks.

    Friday, July 6, 2012 7:40 AM

Answers

  • Hi AliRıza Adıyahşiac,

    Welcome to MSDN Forum.

    You can add a dataannotation on the foreign key.

    [ForeignKey("User")]
    public string user_id { get; set; }

    Best Regards

    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Monday, July 9, 2012 3:21 AM
    Moderator