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

Points:949
Posted on    February-02-2016 10:29 PM

 ASP.Net C#  ASP.Net  ASP.NET MVC 
Ratings:


 1 Reply(s)
 358  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:153

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

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

Follow MindStick