Reputation: 525
I am having trouble getting this list to save to the database, I have stepped through the code and everything executes but the changes are not saved to the database.
This is the list in the model, this is also where I am initializing it:
public List<Event> BandEvents { get; set; }
public Band()
{
BandEvents = new List<Event>();
}
This is the controller method where I am saving the data:
db.Bands.Find(BandID).BandEvents.Add(@event);
db.SaveChanges();
After the db.SaveChanges()
has been executed I ran the following code in my immediate window: db.Bands.Find(9).BandEvents.ToList();
, and I can see the item has been added to the list but this is not saving and when I try to pull the list elsewhere it is empty.
Upvotes: 0
Views: 888
Reputation: 13182
You need to define relationship between those types. Have a look at Configure One-to-Many Relationship.
Upvotes: 2