title: Why is Entity Framework not saving enum properties on my model properly?
body: <p>Here is my model with their related enums below
  which I am using with entity framework 5 and asp.net mvc4 codefirst.
  I am also using portable database file(.mdf)</p>
  
  <pre><code>public class Project
      {
          public Project()
          {
              Images = new List&lt;ProjectImage&gt;();
          }
  
          public int ProjectId { get; set; }
          [Required]
          public string Title { get; set; }
          public virtual ICollection&lt;ProjectImage&gt; Images { get; set; }
          public string Description { get; set; }
          public ProjectType Type { get; set; }
          public ProjectState State { get; set; }
      }
  
      public enum ProjectType
      {
          Phone,
          Web,
          Windows
      }
  
      public enum ProjectState : byte
      {
          InProgress,
          NotStarted,
          Done
      }
  </code></pre>
  
  <p>After posting back the model from a view, all the fields get saved to the database properly except the enum fields. They get saved but will only save the first values of each enum type even after selecting different values in the view.</p>
  
  <p>I have tried saving edits as well and the same happens.</p>
  
  <p>I have stepped through the beginning of my create post method and all seems ok after calling savechanges on my context but when I redirect back to the index page, it shows the enum property values as the initial ones on the enums( i.e. the first enum values)</p>
  
  <p>My create and edit methods are below. Hopefully its not a bug but please help as I have been pulling my hair out for couple of days with this. I'm just starting out with codefirst and enums together. Thanks.</p>
  
  <p>Create post Method</p>
  
  <pre><code>[HttpPost]
          public ActionResult Create(Project project, HttpPostedFileBase file)
          {
              try
              {
                  if (file != null &amp;&amp; file.ContentLength &gt; 0 &amp;&amp; file.ContentType.Contains("image"))
                  {
                      //create a new unique filename with using guid, filename and project title
                      string relativePath = Constants.PortfolioImagesBaseFolder + 
                                          project.Title.Replace(" ", "") + 
                                          Guid.NewGuid().ToString() +
                                          Path.GetFileName(file.FileName);
  
                      string absolutePath = Server.MapPath(relativePath);
  
                      //save the file
                      file.SaveAs(absolutePath);
  
                      if (ModelState.IsValid)
                      {
                          project.Images.Add(new ProjectImage()
                          {
                              IsProjectMainImage = true,
                              Url = relativePath,
                              Title = "Main Project Image"
                          });
                          context.Projects.Add(project);
                          context.SaveChanges();
  
                          return RedirectToAction("Index");
                      }
                  }
  
                  ViewBag.ProjectTypes = CreateSelectListFromEnumType&lt;ProjectType&gt;();
  
                  ViewBag.ProjectStates = CreateSelectListFromEnumType&lt;ProjectState&gt;();
  
                  return RedirectToAction("Index");
              }
  </code></pre>
  
  <p>Edit Post method</p>
  
  <pre><code>[HttpPost]
          public ActionResult Edit(int id, Project project)
          {
              try
              {
                  if (ModelState.IsValid)
                  {
                      //Project projectFromDb = context.Projects.Single(p =&gt; p.ProjectId == id);
                      //projectFromDb.State = project.State;
                      //projectFromDb.Type = project.Type;
                      //projectFromDb.Title = project.Title;
                      //projectFromDb.Description = project.Description;
                      EntityState entityState = context.Entry(project).State;
                      context.Entry(project).State = EntityState.Modified;
                      context.SaveChanges();
                      return RedirectToAction("Index");
                  }
  
                  ViewBag.ProjectTypes = CreateSelectListFromEnumType&lt;ProjectType&gt;();
  
                  ViewBag.ProjectStates = CreateSelectListFromEnumType&lt;ProjectState&gt;();
  
                  return View(project);
              }
  </code></pre>
  
  <p>Also before marking as duplicate, I have looked at many answers on stackoverflow and none could help me, cheers, hence the wait for two days before asking the question.</p>