I am making an application in mvc .net core and when scaffolding the data model I get this error:
entity type Users has no key defined, define the key for this entitytype
Does Anyone Know How to Solve this Error?
I have tried everything, but I think the solution has to come from VB.Net Because the Solutions from C# have Not Worked for Me
Public Class Usuarios
<Key>
Public Id As Integer
Public Nombre As String
Public Clave As String
Public FechaAlta As DateTime
Public Comunidad As String
Public comunidades As SelectListItem
Public Ciudad As String
Public Rol As Integer
End Class
Greetings
ffb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
3
I think, that the problem is, that you declared fields instead of properties. Since a property with the name Id
or <entity name>Id
, e.g., UsuariosId
, will automatically be recognized as key, the <Key>
attribute is not required in this case.
Public Class Usuarios
Public Property Id As Integer
Public Property Nombre As String
Public Property Clave As String
Public Property FechaAlta As DateTime
Public Property Comunidad As String
Public Property comunidades As SelectListItem
Public Property Ciudad As String
Public Property Rol As Integer
End Class
See also:
- Keys – EF Core
- Automatically implemented properties (Visual Basic)