I followed the tutorial:http://www.asp.net/entity-framework/tutorials/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application
</div>
The tutorial you referenced uses the Code First approach. As such, there is no need to create and edmx file. Also, there are a number of typographical errors between the code you posted and the code listed in the tutorial. For example all of the members
of the DbContext should be pluralized and all of the entity classes should be singular. In particular, you have an Enrollments class. This should be singular, i.e. Enrollment (without the "s").
The Code First approach is based on the principle of convention over configuration, which means that you need to follow a specific convention when defining your objects. For example, the key field for an entity should be name either "ID" or the name of the
entity class with "ID" appended to the end. I would suggest you compare you code to the code from the tutorial to identify what needs to be changed.
chohmann
Star
9385 Points
1644 Posts
Re: entity type has no key defined error - help please!
Jun 02, 2011 04:37 PM|LINK
The tutorial you referenced uses the Code First approach. As such, there is no need to create and edmx file. Also, there are a number of typographical errors between the code you posted and the code listed in the tutorial. For example all of the members of the DbContext should be pluralized and all of the entity classes should be singular. In particular, you have an Enrollments class. This should be singular, i.e. Enrollment (without the "s"). The Code First approach is based on the principle of convention over configuration, which means that you need to follow a specific convention when defining your objects. For example, the key field for an entity should be name either "ID" or the name of the entity class with "ID" appended to the end. I would suggest you compare you code to the code from the tutorial to identify what needs to be changed.