none
Entity Error upon creating table RRS feed

  • Question

  • I am getting the following error when try to create a DB table from an entity model. 

    The navigation property 'Resolution' is not a declared property on type 'Events'. Verify that it has not been explicitly excluded from the model and that it is a valid navigation property.

    My Class is below:

    public class Events
            {
                [Key]
                public int ID { get; set; }
                [Required]
                [StringLength(1000, ErrorMessage = "Description Max Length is 1000")]
                public String EventShortDescription { get; set; }
                [Required]
                public String EventLongDescription { get; set; }
                [Required]
                [StringLength(16, ErrorMessage = "Description Max Length is 16")]
                public String IPAddress { get; set; }
                [Required]
                [StringLength(30, ErrorMessage = "Description Max Length is 30")]
                public String MachineName { get; set; }
                [Required]
                [StringLength(20, ErrorMessage = "Description Max Length is 20")]
                public String AlternatePhone { get; set; }
                [Required]
                [StringLength(1000, ErrorMessage = "Description Max Length is 1000")]
                public String Resolution { get; set; }
                [Required]
                public DateTime OpenedDateTime { get; set; }
                [Required]
                public int CustomerID { get; set; }
                [Required]
                public Customer Customer { get; set; }
                [Required]
                public int AssignedWorkGroupID { get; set; }
                [Required]
                public WorkGroups AssignedWorkGroup { get; set; }
                [Required]
                public int AssetID { get; set; }
                [Required]
                public Assets Asset { get; set; }
                [Required]
                public int ConfigurableID { get; set; }
                [Required]
                public Configurables Configurable { get; set; }
                [Required]
                public int ServiceID { get; set; }
                [Required]
                public Services Service { get; set; }
                [Required]
                public int EventTypeID { get; set; }
                [Required]
                public EventTypes EventType { get; set; }
                [Required]
                public int IssueTypeID { get; set; }
                [Required]
                public IssueTypes IssueType { get; set; }
                [Required]
                public int IssueSubTypeID { get; set; }
                [Required]
                public IssueSubTypes IssueSubType { get; set; }
                [Required]
                public int SeverityID { get; set; }
                [Required]
                public Severities Severity { get; set; }
                [Required]
                public int ImmediacyID { get; set; }
                [Required]
                public Immediacies Immediacy { get; set; }
                [Required]
                public int PriorityID { get; set; }
                [Required]
                public Priorities Priority { get; set; }
                [Required]
                public int OpenGroupID { get; set; }
                [Required]
                public WorkGroups OpenGroup { get; set; }
                [Required]
                public int OpenedByID { get; set; }
                [Required]
                public Users OpenedBy { get; set; }
                [Required]
                public int ClosureCodeID { get; set; }
                [Required]
                public ClosureCodes ClosureCode { get; set; }
                [Required]
                public int ResolutionCodeID { get; set; }
                [Required]
                public ResolutionCodes ResolutionCode { get; set; }
                [Required]
                public int EventStatusID { get; set; }
                [Required]
                public EventStatuses EventStatus { get; set; }
            }

    I have done some research, this error appears to come up when there is a lot of overrides done to the OnModelCreating method.  This is what I have done for the Events Class in OnModelCreating:

    modelBuilder.Entity<Events>().HasRequired(a => a.Customer).WithMany().HasForeignKey(b => b.CustomerID);
                modelBuilder.Entity<Events>().HasRequired(a => a.AssignedWorkGroup).WithMany().HasForeignKey(b => b.AssignedWorkGroupID).WillCascadeOnDelete(false);
                modelBuilder.Entity<Events>().HasRequired(a => a.Asset).WithMany().HasForeignKey(b => b.AssetID).WillCascadeOnDelete(false);
                modelBuilder.Entity<Events>().HasRequired(a => a.Configurable).WithMany().HasForeignKey(b => b.ConfigurableID).WillCascadeOnDelete(false);
                modelBuilder.Entity<Events>().HasRequired(a => a.Service).WithMany().HasForeignKey(b => b.ServiceID).WillCascadeOnDelete(false);
                modelBuilder.Entity<Events>().HasRequired(a => a.EventType).WithMany().HasForeignKey(b => b.EventTypeID).WillCascadeOnDelete(false);
                modelBuilder.Entity<Events>().HasRequired(a => a.IssueType).WithMany().HasForeignKey(b => b.IssueTypeID).WillCascadeOnDelete(false);
                modelBuilder.Entity<Events>().HasRequired(a => a.IssueSubType).WithMany().HasForeignKey(b => b.IssueSubTypeID).WillCascadeOnDelete(false);
                modelBuilder.Entity<Events>().HasRequired(a => a.Severity).WithMany().HasForeignKey(b => b.SeverityID).WillCascadeOnDelete(false);
                modelBuilder.Entity<Events>().HasRequired(a => a.Priority).WithMany().HasForeignKey(b => b.PriorityID).WillCascadeOnDelete(false);
                modelBuilder.Entity<Events>().HasRequired(a => a.Immediacy).WithMany().HasForeignKey(b => b.ImmediacyID).WillCascadeOnDelete(false);
                modelBuilder.Entity<Events>().HasRequired(a => a.OpenGroup).WithMany().HasForeignKey(b => b.OpenGroupID).WillCascadeOnDelete(false);
                modelBuilder.Entity<Events>().HasRequired(a => a.OpenedBy).WithMany().HasForeignKey(b => b.OpenedByID).WillCascadeOnDelete(false);
                modelBuilder.Entity<Events>().HasRequired(a => a.ClosureCode).WithMany().HasForeignKey(b => b.ClosureCodeID).WillCascadeOnDelete(false);
                modelBuilder.Entity<Events>().HasRequired(a => a.Resolution).WithMany().HasForeignKey(b => b.ResolutionCodeID).WillCascadeOnDelete(false);
                modelBuilder.Entity<Events>().HasRequired(a => a.EventStatus).WithMany().HasForeignKey(b => b.EventStatusID).WillCascadeOnDelete(false);

    The property Resolution is supposed to only be a string property and not related to another class.

    • Moved by Bob Shen Monday, July 15, 2013 9:21 AM
    Sunday, July 14, 2013 12:38 AM

Answers

  • Hi Bob,

    You declared Resolution as a string in your Events class:

    [Required]
    [StringLength(1000, ErrorMessage = "Description Max Length is 1000")]
    public String Resolution { get; set; }

    From the documentation, HasRequired method receives a Expression<Func<TEntityType, TTargetEntity>> parameter where TTargetEntity is the type of entity at the other end of the relationship.

    Resolution is a scalar property, however you are using it like a navigation property in OnModelCreating method:

    modelBuilder.Entity<Events>().HasRequired(a => a.Resolution).WithMany().HasForeignKey(b => b.ResolutionCodeID).WillCascadeOnDelete(false);

    You should try to modify your Resolution property to a navigation property to add the relationship.

    Best regards,


    Chester Hong
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

    Wednesday, July 17, 2013 2:19 AM
    Moderator