2
votes

I'm trying to create a MVC 5 controller with views, using Entity Framework. I have a public model class that has protected access modifier on properties which have private set access modifier. Is it possible to create a controller for model that has protected properties with private set?

Model class:

public class Movie
{
    protected int ID { get; private set; }
    protected string Title { get; private set; }
    protected DateTime ReleaseDate { get; private set; }
    protected string Genre { get; private set; }
    protected decimal Price { get; private set; }
}

Connection string:

<add name="MovieDBContext" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=aspnet-MvcMovie;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\Movies.mdf" providerName="System.Data.SqlClient" />

When I try to create that kind of a controller I get an error: enter image description here

I have tried to add [key] prefix before ID property but that didn't help.

1
Your primary key needs to be public access modifier. - Nashmár

1 Answers

0
votes

Your primary key needs to be public access modifier.

 public class Movie
 {
     public int ID { get; private set; }
 }