---
title: "How to use one composite key in a class to another class in model of  ASP.NET MVC4 using code first approach"  
description: "How to use one composite key in a class to another class in model of  ASP.NET MVC4 using code first approach"  
author: "Anupam Mishra"  
published: 2016-02-02  
updated: 2016-02-02  
canonical: https://www.mindstick.com/forum/33950/how-to-use-one-composite-key-in-a-class-to-another-class-in-model-of-asp-dot-net-mvc4-using-code-first-approach  
category: "asp.net"  
tags: ["c#", "asp.net", "asp.net mvc"]  
reading_time: 1 minute  

---

# How to use one composite key in a class to another class in model of  ASP.NET MVC4 using code first approach

Hi Everyone,I have created a [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp) in a [model](https://yourviews.mindstick.com/view/81334/america-is-reopening-after-corona-lockdown-but-on-swedish-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](https://www.mindstick.com/blog/11999/how-to-schedule-architectural-photography-for-your-building-project) in a model and call the above class [primary key](https://www.mindstick.com/blog/214/primary-key) [fields](https://www.mindstick.com/forum/159126/sql-query-for-all-tables-and-fields-in-an-oracle-db) 'ID' in my schedule class

.Please can [anyone give me](https://answers.mindstick.com/qa/41194/can-anyone-give-me-some-high-and-low-points-of-each-of-the-four-first-presidential-administrations) a solution.

Thank you.

## Replies

### Reply by Manoj Bhatt

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; }         ..................    }
```


---

Original Source: https://www.mindstick.com/forum/33950/how-to-use-one-composite-key-in-a-class-to-another-class-in-model-of-asp-dot-net-mvc4-using-code-first-approach

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
