EF 4.1 Code First error - The entity type SomeType is not part of the model for the current context

后端 未结 10 1509
遇见更好的自我
遇见更好的自我 2020-12-10 00:28

While working with EF code first I get error given below at different times:

The entity type SomeType is not part of the model for the current context.

10条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-10 00:57

    UPDATE

    This error kept attacking me with various updates I made to the database. Eventually I deleted the edmx file and just created it again with the same tables and stored procs.

    Old

    I got this when the generated entity was missing a nullable column:

    //------------------------------------------------------------------------------
    // 
    //    This code was generated from a template.
    //
    //    Manual changes to this file may cause unexpected behavior in your application.
    //    Manual changes to this file will be overwritten if the code is regenerated.
    // 
    //------------------------------------------------------------------------------
    
    namespace MyProgram.Models
    {
        using System;
        using System.Collections.Generic;
    
        public partial class Question
        {
            public int id { get; set; }
            public string title { get; set; }
            public string body { get; set; }
            public string tags { get; set; }
            public int votes { get; set; }//I had to manually add this property which is nullable int in the database
        }
    }
    

    I added the property after generating the initial model. However, I even tried deleting the table and recreating it. That didn't fix it. Only adding the property manually fixed it for me.

提交回复
热议问题