Relationship between 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
        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.


    Friday, July 6, 2012 7:40 AM


  • Hi AliRıza Adıyahşiac,

    Welcome to MSDN Forum.

    You can add a dataannotation on the foreign key.

    public string user_id { get; set; }

    Best Regards

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

    Monday, July 9, 2012 3:21 AM