Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Changed Model and now I get a "Build Failed" error

$
0
0

I'm hoping someone can help me.  I'm trying to update my models.  I've added a new model that is essentially the same as another model but with updated relations.  I can not get the migrations to work.  I keep getting a "Build Failed" error.  I've tried adding -v to see if I can see the error, but nothing comes of it.   I created a new project and tried just the new model and the existing model that has the relationship with it and that works fine.  

So what I'm trying to do:

Currently I have a  Course Model that is in a a one to many relationship with a Objective Model.  There are also other models that have a one-to-many relationship with the Objective Model.  I want to change it so I have multiple Objective Models (Named Differently) and have it so the relation is only with one model.

So, right now I have:

  • Course, Unit, Section, and Subsection all with a one-to-many relationship with Objective

I want to change it to:

  • Course one-to-many with ObjectiveCourse
  • Unit one-to-many with UnitCourse
  • etc.

Original Model for Objective:

public class Objective
{
[Required]
[Key]
[Display(Name = "Objective ID")]
public int ID { get; set; }

[Required]
[Display(Name = "Objective")]
[StringLength(2000)]
public string Description { get; set; }

[Display(Name = "Objective Number")]
public int ObjectiveNumber { get; set; }

public int? SubsectionID { get; set; }
public Subsection Subsection { get; set; }

public int? UnitID { get; set; }
public Unit Unit { get; set; }

public int? SectionID { get; set; }
public Section Section { get; set; }

public int? CourseID { get; set; }
public Course Course { get; set; }
}

New Model ObjectiveCourse:

    public class ObjectiveCourse
    {
        [Required]
        [Key]
        [Display(Name = "Objective ID")]
        public int ID { get; set; }

        [Required]
        [Display(Name = "Objective")]
        [StringLength(2000)]
        public string Description { get; set; }

        [Display(Name = "Objective Number")]
        public int ObjectiveNumber { get; set; }

        public int? CourseID { get; set; }
        public Course Course { get; set; }
    }

Updated Course Model:

    public class Course
    {
        [Required]
        [Key]
        [Display(Name = "Course ID")]
        public int ID { get; set; }

        [Required(ErrorMessage = "This field is required.")]
        [Display(Name = "Course Number")]
        public string CourseNumber { get; set; }

        [Required(ErrorMessage = "This field is required.")]
        [Display(Name = "Course Title")]
        [StringLength(200)]
        public string Title { get; set; }

        [Display(Name = "Course Description")]
        [StringLength(2000)]
        public string Description { get; set; }

        // Match email to current user.  
        [Required(ErrorMessage = "This field is required.")]
        [Display(Name = "Course Owner's Email")]
        [DataType(DataType.EmailAddress)]
        public string Email { get; set; }

        public IList<Unit> Units { get; set; }

        public IList<ObjectiveCourse> ObjectivesCourse { get; set; }
    }

I have tried to delete my database and migrations and start over, but no luck. I've also updated my DBContext.

Any thoughts?

Is there something in some file somewhere that may not be getting updated? 

Thanks in advance.


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>