DBContext Method not found (System.MissingMethodException on OnModelCreating())

ef-code-first ef-code-first-mapping entity-framework-6


I've been stuck with below exception from OnModelCreating() in DBContext and struggling to find the cause or a solution. Can't find much help online either.

 {System.MissingMethodException: Method not found: 'System.Nullable`1<Int32> Models.Application.get_AddrSeqNum()'. at Data.Configuration.ApplicationConfiguration..ctor()

Any help or ideas please?


I've two entity types 'Application' and 'Organization' and their Entity Type Configurations as below:

public  class Application
   public int ApplId { get; set; }
   public int? OrganizationId { get; set; } // Compsite FK (maps to ExternalId in Organization)
   public int? AddrSeqNum { get; set; } // Compsite FK (maps to AddrSeqNum)
   public virtual Organization Organization { get; set; }     

public class Organization
    public int Id { get; set; }
    /// <summary>
    /// Organization ID
    /// </summary>
    public int ExternalId { get; set; }
    public int AddrSeqNum { get; set; }        

public class ApplicationConfiguration : EntityTypeConfiguration<Application>

    HasKey(e => e.ApplId)
      .Property(e => e.ApplId)

     Property(e => e.AddrSeqNum)

     // Relationship
     HasOptional(e => e.Organization)
            .HasForeignKey(e => new { e.OrganizationId, e.AddrSeqNum });

public class OrganizationConfiguration : EntityTypeConfiguration<Organization>
    public OrganizationConfiguration()

        HasKey(e => new { e.ExternalId, e.AddrSeqNum }); // Compsite Unique key in table

        Property(e => e.ExternalId)

        Property(e => e.AddrSeqNum)

        Property(e => e.Id)
            .HasColumnName("Id") // Primary key (auto increment)


public partial class AppDbContext : DbContext
    public AppDbContext ()
        Configuration.LazyLoadingEnabled = true;
        Configuration.ProxyCreationEnabled = false;
        //Configuration.AutoDetectChangesEnabled = false;

        DbInterception.Add(new FtsInterceptor());
        Database.Log = (msg) => Logger.Debug(msg);

    protected override void OnModelCreating(DbModelBuilder modelBuilder)

        modelBuilder.Configurations  // <<- Exception from here
            .Add(new ApplicationConfiguration())                
            .Add(new OrganizationConfiguration())
9/24/2019 4:31:46 PM

Popular Answer

I was having this problem too, because I made a nullable database column non-nullable and Visual Studio didn't seem to want to cooperate with the change.

Deleting bin and obj folders, as well as rebuilding, didn't seem to do it.

As a workaround, I just made it nullable again. It's interesting because I'm not sure where VS is caching the nullable part--a question to be answered when I'm under less tight deadlines. :)

4/13/2017 10:31:21 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow