Error running Updade-Database command

Asked

Viewed 26 times

3

When executing the command Update-Database Package Manager Console gets the following error:

Value cannot 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 didn’t identify why that mistake.

What causes this mistake? How can I fix it ?

  • 2

    A lot of things can cause this mistake. Post the models.

  • @LINQ For now I have only this model that I inserted in the question edition!

  • Take a test there, change the name of your class to ProjectTeste

  • @LINQ same error! ;(

  • 1

    Ah, young man. It’s because you have a property like HttpPostedFileBase...

1 answer

4


This is because there is a property that cannot be mapped. In this case, it is the property Image who’s kind HttpPostedFileBase.

Add the attribute [NotMapped] on 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; }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.