0
votes

Have Breeze setup with WebAPI and EntityFramework.

EntityManager queries working fine. SaveChanges() working fine on all entities, EXCEPT...

I have an entity with an optional related entity:

Public Class Payment
    Public Property Id As Integer
    Public Overridable Property Registree As Registree
    Public Property RegistreeId as Integer?
    Public Property Amount as Double
End Class

Here is my WebAPI action for SaveChanges()

  <HttpPost()>
    Public Function SaveChanges(bundle As JObject) As SaveResult
        Dim result As SaveResult
        Try
            result = breezeDb.SaveChanges(bundle)
        Catch ex As Exception
            Dim err = ex
        End Try
        Return result
    End Function

When I create a new Payment entity in Breeze and call SaveChanges, everything works fine UNLESS my payment entity has a value for RegistreeId.

If RegistreeId has a value, the following happens:

  1. SaveChanges() on the WebAPI is successfully called.
  2. No errors are caught in my Try/Catch.
  3. The "result" returned to the client has no errors associated with it.

However, on client side, the manager.saveChanges() fails, giving an error object with NO details, just "The response had HTTP status code 500."

return manager.saveChanges()
              .then(function(saveResult){
                return saveResult;
              })
              .catch(errorOnSave); //this gets called, no breakpoints get hit in the "then" function

NOTE: The entity IS getting saved correctly to the database, related entity and all. So this is not a foreign key constraint or other database problem.

So it seems something is breaking on the server and no error message is getting to client. But my try/catch is not getting it, and the error ONLY happens if that optional foreign key field is NOT null.

Any ideas?

1

1 Answers

2
votes

Found the problem...didn't realize I had not turned off Custom Errors in web.config.

<system.web>
    <customErrors mode="Off" />
  ...
  </system.web>

Then I was able to see that Json.Net was running into null exception error when parsing the saveresult.