Value cannot be null. Parameter name: entitySet

前端 未结 12 1792
夕颜
夕颜 2020-12-03 17:02

I have a fairly standard setup with simply POCO classes

public class Project
{

    public int ProjectId { get; set; }
    public string Name { get; set; }
          


        
相关标签:
12条回答
  • 2020-12-03 17:29

    I got this error when I declared a variable of type Type - which is probably because is a complex type not supported by the DB.

    When I changed it to string, the error went away

    public class Sample
    {
      public int SampleID {get;set;}
      public Type TypeInfo {get; set;} //This caused the error, 
                                       //because Type is not directly convertible 
                                      //in to a SQL datatype
    }
    
    0 讨论(0)
  • 2020-12-03 17:33

    I had the same issue and the cause was a POCO class that had a property of type Type.

    0 讨论(0)
  • 2020-12-03 17:33

    This problem can occur if one of the POCO classes was not declared in the DbContext.

    I added them and the error went away

    I had changed the name of the Task POCO class because of its association with a built in .NET name System.Threading.Tasks. However I had not changed this in the "TaskTimeLog" POCO where there was a relation. When going through the code the "Task" property in the "TaskTimeLog" POCO was not showing an error because it was now attached to that threading keyword and the reason I had changed the name in the first place.

    0 讨论(0)
  • 2020-12-03 17:39

    In my case I had to reference another model class called IanaTimeZone, but instead of

    public virtual IanaTimeZone Timezone { get; set; }
    

    out of rush I typed this:

    public virtual TimeZone Timezone { get; set; }
    

    and it compiled fine because VS thought it was System.TimeZone but EF6 was throwing the error. Stupid thing but took me a while to figure out, so maybe this will help someone.

    0 讨论(0)
  • 2020-12-03 17:40

    Remove the line <Generator>EntityModelCodeGenerator</Generator> from your project file.

    Check out this https://www.c-sharpcorner.com/UploadFile/5d065a/poco-classes-in-entity-framework/

    0 讨论(0)
  • 2020-12-03 17:41

    For anyone not finding a resolution in the other answers, I got this error when I created a derived class from a class that had an instance in some model. The exception occurred on the first usage of my context in a request.

    This is a stripped-down example that will reproduce the behaviour. Model is a DbSet in my context.

    public class Model
    {
        public int Id { get; set; }
        public Duration ExposureDuration { get; set; }
    }
    
    public class Duration
    {
        public int Value { get; set; }
        public string Unit { get; set; }
    }
    
    //Adding this will cause the exception to occur.
    public class DurationExtended : Duration
    { }
    

    This happened during work in progress. When I changed the model property ExposureDuration to type DurationExtended, all was working again.

    0 讨论(0)
提交回复
热议问题