EntityType 'ApplicantPosition' hat keine Schlüssel definiert

Beim laufen meinen ersten asp.net mvc-Anwendung bekam ich diese Fehlermeldung
Ich dachte, dass entity framework automatisch erstellen würde, die Schlüssel-Spalte-Namen mit der Id? ist es nicht richtig?

Wie Sie sehen können die ApplicantPositionID wäre eine Tabelle mit 2 Spalten als primary key, denn es würde sich auf die Bewerber und auch zu Positionieren.

Einen oder mehrere Fehler bei der Validierung festgestellt wurden, während Modell-generation:

System.Data.Edm.EdmEntityType: : EntityType 'ApplicantImage' has no key defined. Define the key for this EntityType.
System.Data.Edm.EdmEntityType: : EntityType 'ApplicationPositionHistory' has no key defined. Define the key for this EntityType.
System.Data.Edm.EdmEntitySet: EntityType: EntitySet ApplicantsPositions is based on type ApplicantPosition that has no keys defined.
System.Data.Edm.EdmEntitySet: EntityType: EntitySet ApplicantImages is based on type ApplicantImage that has no keys defined.
System.Data.Edm.EdmEntitySet: EntityType: EntitySet ApplicationsPositionHistory is based on type ApplicationPositionHistory that has no keys defined.

Den Fehler in dieser Zeile:

public ActionResult Index()
        {
            return View(db.Positions.ToList());
        }

Und mein Modell ist das folgende:

namespace HRRazorForms.Models
{



    public class Position
    {
        public int PositionID { get; set; }
        [StringLength(20, MinimumLength=3)]
        public string name { get; set; }
        public int yearsExperienceRequired { get; set; }
        public virtual ICollection<ApplicantPosition> applicantPosition { get; set; }
    }

    public class Applicant
    {
        public int ApplicantId { get; set; }
        [StringLength(20, MinimumLength = 3)]
        public string name { get; set; }
        public string telephone { get; set; }
        public string skypeuser { get; set; }
        public ApplicantImage photo { get; set; }
        public virtual ICollection<ApplicantPosition> applicantPosition { get; set; }

    }

    public class ApplicantPosition
    {
        public int ApplicantID { get; set; }
        public int PositionID { get; set; }
        public virtual Position Position { get; set; }
        public virtual Applicant Applicant { get; set; }
        public DateTime appliedDate { get; set; }
        public int StatusValue { get; set; }

        public Status Status
        {
            get { return (Status)StatusValue; }
            set { StatusValue = (int)value; }
        }

        //[NotMapped]
        //public int numberOfApplicantsApplied
        //{
        //   get
        //   {
        //       int query =
        //            (from ap in Position
        //             where ap.Status == (int)Status.Applied
        //             select ap
        //                 ).Count();
        //       return query;
        //   }
        //}
    }




    public class ApplicantImage
    {
        public int ApplicantId { get; private set; }
        public byte[] Image { get; set; }
    }

    public class Address
    {
        [StringLength(20, MinimumLength = 3)]
        public string Country { get; set; }
        [StringLength(20, MinimumLength = 3)]
        public string City { get; set; }
        [StringLength(20, MinimumLength = 3)]
        public string AddressLine1 { get; set; }
        public string AddressLine2 { get; set; }    
    }



    public class ApplicationPositionHistory
    {
        public ApplicantPosition applicantPosition { get; set; }
        public Status oldStatus { get; set; }
        public Status newStatus { get; set; }
        [StringLength(500, MinimumLength = 10)]
        public string comments { get; set; }
        public DateTime dateModified { get; set; }
    }

    public enum Status
    {
        Applied,
        AcceptedByHR,
        AcceptedByTechnicalDepartment,
        InterviewedByHR,
        InterviewedByTechnicalDepartment,
        InterviewedByGeneralManager,
        AcceptedByGeneralManager,
        NotAccepted
    }



}

InformationsquelleAutor Luis Valencia | 2011-10-14

Schreibe einen Kommentar