I'm sure that this is very straight-forward, however, after scouring the net I can't find anything to set me straight.

I am using ASP.NET MVC 3 with the Entity Framework Code-first modeling.

I have a simple one-to-many relationhip between a Calendar and an Event (For each calendar there can be 0 or more Events).

Simply put, I am confused as to how to create/insert a new event associated with a calendar.

My entity domain definitions are:

```
public class Calendar
{
    [Key]
    public long id { get; set; }
    public string title { get; set; }
    public string description { get; set; }
    public virtual ICollection<Event> events { get; set; }
} //class

public class Event
{
    [Key]
    public long id { get; set; }          
    public string title { get; set; }
    public string description { get; set; }
    public DateTime startdate { get; set; }
    public DateTime enddate { get; set; }
    public int importance { get; set; }
} //class

```

I have created a page with a link to "Create a new event" that passes the Calendar id to the CalendarController action named Create (/localhost:xxxxx/Calendar/Create/1). 

I am stuck at this point as with code-first, I do not have the calendar\_id (or something like it) as a specified member of the Event class to associate the event to a calendar. This does exist in the database as the column was generated by the code-first engine.

I tried creating a ViewModel combining the calendar id and an Event object, however, when I return from the Create.cshtml the calendar id was reset from 1 to 0, although the event information was valid.

In closing, in a one-to-many relationship (as above), how do you create a new event (the many side) with a calendar (the one side)? I'm sure it is quite simple, and I'm missing something, but any and all help will be appreciated.

/***\**\*\**\**\*\**\**\*\**\**\*\**\**\*\**\****/

Here is a bit more detail that I hope will add clarification to my problem.

1. A user selects a Calendar (calendar\_id, let's say it is 1).
2. On a detail page for that particular calendar, there is a link to a controller/action (CalendarController/CreateEvent) to create a new event associated with that particular calendar.
The created route is Calendar/CreateEvent/1 (create a new event for calendar with id==1).
3. In the CreateEvent action, I now have the id for the calendar instance for the new event.

This is where I get confused...

The Event object does not have a calendar\_id data member as that is created by the code-first engine, so I have nothing to assign the calendar\_id that arrived in the route data.

I know that this is a standard situation, but I'm missing something. I need to keep the calendar\_id through to the [HttpPost]CreateEvent. From there, I can simply find the proper calendar (using calendar\_id), take the info from the new Event form (in CreateEvent.cshtml) to create a new event, and simply call Calendar.Add(newEvent). 

How do I keep the calendar\_id (or the calendar for that matter) through the whole GET/form/POST cycle?

Thanks again for any help.

/***\**\*\**\**\*\**\**\*\**\**\*\**\**\*\**\****/
I re-tried the possible solution mentioned below to add a virtual Calendar and CalendarId to the Event class. I changed the action parameter accepted to an Event object for both the HttpGet and HttpPost functions. In the HttpGet function I set the CalendarId to that of the Calendar to which the new event will be added (as above,the id == 1). Everything worked fine in the CreateEvent view, however, on the return to the HttpPost action of CreateEvent, the CalendarId was reset to 0.

I'm still missing something... but thank you for the help,and I'm still looking for that spark.