Home > DeveloperSection > Forums > 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

Posted on    February-02-2016 10:29 PM


 1 Reply(s)
 531  View(s)
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.

Manoj Bhatt
Manoj Bhatt

Total Post:154

Posted on    February-02-2016 10:59 PM

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
        [Column(Order = 0)]
        public int LocationID { get; set; }

Don't want to miss updates? Please click the below button!

Follow MindStick