Reputation: 759
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:
I have tried to add [key]
prefix before ID property but that didn't help.
Upvotes: 2
Views: 172
Reputation: 392
Your primary key needs to be public
access modifier.
public class Movie
{
public int ID { get; private set; }
}
Upvotes: 0