Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8383507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:10:47+00:00 2026-06-09T17:10:47+00:00

I am currently working on a Web API project with a Database-First method using

  • 0

I am currently working on a Web API project with a Database-First method using Entity Framework (which I know is not the most stable of platforms yet), but I am running into something very strange.

When the GET method within my APIController tries to return all records in a DbSet with a LINQ Include() method involved such as this, it will return a 500 error:

// GET api/Casinos
    public IEnumerable<casino> Getcasinos()
    {
            var casinos = db.casinos.Include(c => c.city).Include(c => c.state);
            return casinos.AsEnumerable();
        }

Yet, this method works fine, and returns my data from within my database:

// GET api/States
    public IEnumerable<state> Getstates()
    {
        return db.states.AsEnumerable();
    }

So I have proved in other instances that if it returns the entities without LINQ queries, it works great, yet when there is an Include method used upon the DbContext, it fails.

Of course, trying to find this error is impossible, even with Fiddler, Chrome/Firefox dev tools, and adding in GlobalConfiguration.Configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;

If anyone has resolved this, it would be nice to know a nice resolution so I can start returning my data! Thanks!:)

P.S. I am using SQL Server 2012

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:10:48+00:00Added an answer on June 9, 2026 at 5:10 pm

    This is happening due to error in serialization (Json/XML). The problem is you are directly trying to transmit your Models over the wire. As an example, see this:

    public class Casino
    {
        public int ID { get; set; }
        public string Name { get; set; }
    
        public virtual City City { get; set; }
    }
    
    public class State
    {
        public int ID { get; set; }
        public string Name { get; set; }
    
        [XmlIgnore]
        [IgnoreDataMember]        
        public virtual ICollection<City> Cities { get; set; }
    }
    
    public class City
    {
        public int ID { get; set; }
        public string Name { get; set; }
    
        public virtual  State State { get; set; }
    
        [XmlIgnore]
        [IgnoreDataMember]
        public virtual ICollection<Casino> Casinos { get; set; }
    }
    
    public class Context : DbContext
    {
        public Context()
            : base("Casino")
        {
    
        }
    
        public DbSet<Casino> Casinos { get; set; }
        public DbSet<State> States { get; set; }
        public DbSet<City> Cities { get; set; }
    }
    

    Pay attention to the XmlIgnore and IgnoreDataMember. You need to restrict avoiding serialization so it doesn’t happen in circular manner. Further, the above model will still not work because it has virtual. Remove virtual from everywhere namely City, Cities, Casinos and State and then it would work but that would be inefficient.

    To sum up: Use DTOs and only send data that you really want to send instead of directly sending your models.

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently working on MVC4 SinglePage Application. I have a Web Api method
First, some context: I'm currently working on a project in which I use the
I am currently using the WCF Web API and it is working great with
I'm currently working on web application using VB in ASP.NET. Right now I have
I am currently working on a web app using Wicket and started using jQuery
I am currently working on a web application. I was just wondering which has
Hello Ruby/Rails/Merb developers! Im currently working on a web project that will have a
Currently the project I'm working with does not have completely fixed models (due to
I am currently working on a project that uses a Google Earth API library
I'm writing a web application using the google maps api v3, which displays places

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.