Base solution for your next web application
Open Closed

Getting 500 error when child entities are added #695

joemo created

I have created a Customer entity...

public string Name {get;set;}

public virtual ICollection<Document> Documents { get; set; }

public Customer()
            Documents = new HashSet<Document>();

... which as you can see each contain Document collections...

public string Type {get;set;}

public virtual int CustomerId { get; set; }
public virtual Customer Customer { get; set; }

And in my DTOs I just declare and set the CustomerId... (not the virtual Customer - this seems to be how you do it in the SimpleTaskSystem example)...

public class CreateDocumentInput : IInputDto
    public string Type {get;set;}

    public in CustomerId {get;set;}

public void CreateDocument(CreateDocumentInput input)
    var document = new Document 
        Type = input.Type,
        CustomerId = input.CustomerId

I've written application services that read and write to both these entities. This all works fine UNTIL I start adding Document entities, and then the original GetCustomers web service call fails with a 500 internal server error. It seems to be because I have added related Documents to the Customer and it is having problems getting the data. Where am I going wrong? I've read outside of ABP that this can happen with lazy loading. Adding this line to DBContext prevents the error:-

this.Configuration.ProxyCreationEnabled = false;

But I don't want to break the benefits of ABP...

1 Answer(s)
  • 0
    hikalkan created
    Support Team

    Can you share stacktrace or full error message? If you are returning entities to the client, is may be a serialization problem. Use return DTOs instead.