Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8896611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:06:53+00:00 2026-06-15T00:06:53+00:00

Maybe a simple question, but I can’t seem to figure it out. Saving a

  • 0

Maybe a simple question, but I can’t seem to figure it out. Saving a collection to a model when adding a model to the database isn’t working. I have a site which uses asp.net MVC and entity framework.

The models:

public class Event
{
    public int Id { get; set; }

    public string Name { get; set; }
    public string Description { get; set; }

    public ICollection<EventRange> Ranges { get; set; }
}

public class EventRange
{
    public int Id { get; set; }

    public string RangeName { get; set; }
    public string RangeDescription { get; set; }

    public int Capacitiy { get; set; }
}

The controller actions:

[HttpPost]
public ActionResult Create(Event model)
{
    ICollection<EventRange> eventRanges = new Collection<EventRange>();
    var range = new EventRange {RangeName = "testrange", RangeDescription = "test", Capacitiy = 5}

    eventRanges.Add(range);
    model.Ranges = eventRanges;

    db.Events.Add(model);
    db.SaveChanges();

    return View();
}

public ActionResult Events()
{
    return View(db.Events);
}

When setting a breakpoint in the Events action and evaluated the query, the Range isn’t saved to the event:

Code Screenshot

Note that that the database created for the eventrange model by EF does save the range:

EF DB Screenshot

Am I doing something wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T00:06:54+00:00Added an answer on June 15, 2026 at 12:06 am

    What if you mark the Ranges property as virtual?

    public virtual ICollection<EventRange> Ranges { get; set; }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Maybe it's a simple question but I can't figure out the right way to
Maybe this is a simple question, but I can't figure it out how can
Maybe this is a very simple question, but I just can not figure out.
Maybe a simple question but I can't seem to get it. I want to
simple question maybe but can't find solution. I have button for refresh/update some contents
Simple question, but this gives me an error and I can't seem to resolve
this is a dumb question but for some reason i can't figure it out
This maybe a really simple question but for some reason my code isn't working.
Maybe this is a very simple question, but I can't find the answer: How
My question is maybe simple but I can't find the answer over the internet

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.