Reputation: 201
Web API Controller calls a stored procedure in an Entity Framework Database-First Model.
The stored procedure inserts an entry into my SQL Server Database and then returns that newly created entry.
The Function Import of the stored procedure is set to return a Complex Type, which is a custom created TagDTO(This DTO is created within TasksModel.tt)
However, I continue to get the error "Self Referencing Loop Detected" when this API method is called.
What am I missing from the below? The stored procedure does insert the data correctly.
TagDTO class:
API Controller code:
Upvotes: 0
Views: 348
Reputation: 812
Make sure that you remove the object from your db context before returning it. I believe this can be done by adding the following Evict method to your db context. This will make it so that it only serializes the immediate values for that object, it will not attempt to serialize Navigation Properties.
// this goes inside of your Context Object, parent class may already implement it
public void Evict(object entity)
{
Entry(entity).State = EntityState.Detached;
}
then use it like this:
dbContext.Evict(entityFrameworkObject);
Upvotes: 1