I have a problem with my code. I have some basics WEB API Controller that works ok (three fields without any foreign keys), but i have a problem with a API Controller that returns a list of objects from the model, and that class has a Foreign key to another class from the model. This throws an error: Here is the Api Controller:
Public Class MaestroProvinciaController
Inherits System.Web.Http.ApiController
Private db As New UnificadorEntities
' GET api/MaestroProvincia
Function GetMaestroProvincias() As IEnumerable(Of MaestroProvincia)
Dim l As IEnumerable(Of MaestroProvincia)
l = db.MaestroProvincia.AsEnumerable()
Return l
End Function
End Class
And here is the Model of MaestroProvincia
Partial Public Class MaestroProvincia
Public Property Codigo As Integer
Public Property Descripcion As String
Public Overridable Property Usuario As ICollection(Of Usuario) = New HashSet(Of Usuario)
End Class
When i consume , to try, from the browser to this address:
......../api/maestroprovincia
I got an error:
Error del servidor
El sistema encontró un error mientras extraía ......../api/maestroprovincia . Es posible que el servidor no esté disponible por mantenimiento o no esté bien configurado.
A continuación se detallan algunas sugerencias:
Volver a cargar esta página web después.
Error HTTP 500 (Internal Server Error): Se encontró una situación inesperada mientras el servidor intentaba cumplir con la solicitud.
When I debug the Controller, put a WATCH (inspect) in the "l"
variable, and the type of the objects of the list it is very strange, instead of MaestroProvincia
type I get system.data.entity.DynamicProxies.MaestroProvincia_D7543654378543
.
All the other API Controllers that returns objects from models without FK does not have any problem.
I would appreciate your help.