HOW TO USE ONE COMPOSITE KEY IN A CLASS TO ANOTHER CLASS IN MODEL OF ASP.NET MVC4 USING CODE FIRST APPROACH

Anupam Mishra

Total Post:135

Points:949
Posted by  Anupam Mishra
 551  View(s)
Ratings:
Rate this:
Hi Everyone,
I have created a class in a model such as follows:
 public class Locations
    { [Key]
        public int LocationID { get; set; }
        public string Location { get; set; }
    }

I want to create another class schedule in a model  and call the above class primary key fields 'ID' in my schedule class

.Please can anyone give me a solution.

Thank you.

  1. Manoj Bhatt

    Post:154

    Points:1086
    Re: How to use one composite key in a class to another class in model of ASP.NET MVC4 using code first approach

    Hi Anupam,

    In  your above problem you use a System.ComponentModel.DataAnnotations and 
    System.ComponentModel.DataAnnotations.Schema namespace for creating a Schedule class in a model for using  a ID of Location class . Code is as a below:
     public class Schedule
        {
            [Key]
            [Column(Order = 0)]
            public int LocationID { get; set; }
             ..................
        }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!