Error when running Updad-Database command

3

When I run the Update-Database command in the Package Manager Console, I get the following error:

  

Value can not be null.   Parameter name: entitySet

I have only one model in the project for now

public class Project
{
    [Key]
    public  Guid ProjectId { get; set; }

    public String Title { get; set; }

    public String Content { get; set; }

    public HttpPostedFileBase Image { get; set; }

    public String Author { get; set; }

    public String FileWay { get; set; }

    [Required]
    public DateTime DateProject { get; set; }

    public DateTime? DateUpdate { get; set; }

    public DateTime DateAudience { get; set; }
}

And my class DBContext :

public class DialogoContext : IdentityDbContext<UserClient,Group , Guid, UserLogin, UserGroup, UserIdentity>
{
    public DialogoContext()
        : base("DialogoContext")
    {
    }

    public static DialogoContext Create()
    {
        return new DialogoContext();
    }

    public DbSet<Project> Projects { get; set; }
}

I did not identify the reason for this error.

What causes this error? How can I resolve it?

    
asked by anonymous 27.10.2017 / 15:01

1 answer

4

This is because there is a property that can not be mapped. In this case, it is the Image property that is of type HttpPostedFileBase .

Add the [NotMapped] attribute in this property

public class Project
{
    [Key]
    public  Guid ProjectId { get; set; }

    public String Title { get; set; }

    public String Content { get; set; }

    [NotMapped]
    public HttpPostedFileBase Image { get; set; }

    public String Author { get; set; }

    public String FileWay { get; set; }

    [Required]
    public DateTime DateProject { get; set; }

    public DateTime? DateUpdate { get; set; }

    public DateTime DateAudience { get; set; }
}
    
27.10.2017 / 15:21