0

I'm building a website using Visual Studio 2012 with MVC4 and Entity Framework 4. I created all my model classes, with all their attributes (with some relationships between them). So far, my classes only have a bunch of attributes (no methods yet).

But whenever I try to create a controller for a class that has a collection in it, I get this error: Unable to retrieve metadata for 'model name'. Value cannot be null. Parameter name: key.

I've googled it and found different solutions, but none of them worked: I tried renaming all my primary key attributes to "Id" (they are also all annotated with [Key]), I also tried commenting out the constructor in the Data Context class, I checked my connection is named DefaultConnection...

This is one of the classes for which I'm being unable to create a controller:

public class JobOffer
    {
        [Key]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
        public int JobOfferId { get; set; }
        public Company Company { get; set; }
        public OfferState State { get; set; }
        public virtual ICollection<OfferApplicant> Applicants { get; set; }
        public virtual ICollection<Requirement> Requirements { get; set; }
    }

(I already tried without the [DatabaseGeneratedAttribute] annotation and it didn't help)

The OfferState class is an abstract class that has 2 subclasses: Open and Closed (they're there to implement a State pattern).

The OfferApplicant class maps 1 JobOffer with 1 Applicant, since that was a many-to-many relationships, so I created a new table.

The Requirement class is also an abstract class that has a few subclasses, like Age, Education, Area, etc., and also a CompositeRequirement, which has a public virtual ICollection Requirements { get; set; } collection (it's a Composite pattern).

The classes don't even have methods yet, all they have are their properties.

Any clues?

Thanks!!

4

0 回答 0