Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I created a very simple MVC 4 with Web API project in visual studio Web Developer 2010.

It tries to connect a SQL Server database and pull out the data from a table.

In the api controller, I wrote:

// GET api/gcurobservation/5
public IQueryable<GCUR_OBSERVATION> Get(int id)
{
    return gcurObsRepo.FindGCURObservationByLocId(id);
}

The repository class, method "FindGCURObservationByLocId" is defined:

// Query Methods
public IQueryable<GCUR_OBSERVATION> FindGCURObservationByLocId(int locId)
{
    var records = from l in db.GCUR_OBSERVATIONs
                  where l.LocationId == locId
                  orderby l.ObservationId
                  select l;

    return records;
}

In the debug mode, I could see each GCUR_OBSERVATION object returned from the query. So I am pretty sure the repository works OK but the controller code threw the following error:

An unhandled exception of type 'System.StackOverflowException' occurred in System.Runtime.Serialization.dll

Any tips? Thanks!

Cheers, Alex

share|improve this question
    
Does GCUR_OBSERVARTION have any Foreign Key / Navigation Properties that might produce a circular reference? –  Jaime Torres Dec 13 '13 at 3:32
    
Yes, GCUR_OBSERVARTION does have foreign keys with another table.But how can I find if that might produce a circular reference? –  alextc Dec 13 '13 at 3:44
    
try using OData queries asp.net/web-api/overview/odata-support-in-aspnet-web-api/… –  Nilesh Dec 13 '13 at 4:06
    
Have checked the foreign key integrity and didn't find any problem with it. –  alextc Dec 13 '13 at 4:29
    
Can you post the definitions of GCUR_OBSERVARTION and also definition of classes on which it depends? –  S. Ravi Kiran Dec 16 '13 at 19:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.