Вопрос по asp.net-mvc, asp.net – ASP.Net Web API правильно показывает в VS, но дает HTTP500

4

Error: User Rate Limit Exceeded

Model

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations.Schema;

namespace MvcApplication6.Models
{
    public class tblCustomerBooking
    {
        [Key()]
        public int customer_id { get; set; }
        public string customer_name { get; set; }
        public string customer_email { get; set; }
        public virtual ICollection<tblRental> tblRentals { get; set; }
    }

    public class tblRental
    {
        [Key()]
        public int rental_id { get; set; }
        public int room_id { get; set; }
        public DateTime check_in { get; set; }
        public DateTime check_out { get; set; }
        public decimal room_cost { get; set; }
        public int customer_id { get; set; }
        [ForeignKey("customer_id")]
        public virtual tblCustomerBooking tblCustomerBooking { get; set; }
    }
}

Error: User Rate Limit Exceeded

using System.Data.Entity;

namespace MvcApplication6.Models
{
    public class BookingsContext : DbContext
    {
        public BookingsContext() : base("name=BookingsContext")
        {
        }
        public DbSet<tblCustomerBooking> tblCustomerBookings { get; set; }
    }
}

Error: User Rate Limit Exceeded

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
using MvcApplication6.Models;

namespace MvcApplication6.Controllers
{
    public class BookingsController : ApiController
    {
        private BookingsContext db = new BookingsContext();

        // GET api/Bookings
        public IEnumerable<tblCustomerBooking> GettblCustomerBookings()
        {
            return db.tblCustomerBookings.AsEnumerable();
        }
    }
}

Error: User Rate Limit Exceeded

Snapshot of customer and rental objects

Error: User Rate Limit ExceededFiddler screenshot showing HTTP500

Есть ли еще код, который я могу добавить в контроллер, чтобы увидеть, почему он дает ошибку? Или кто-нибудь может увидеть, что может быть не так? VS, кажется, получает его нормально, как показано на первом снимке экрана, но, похоже, не может его отправить.

Спасибо за любую помощь или указатели,

отметка

Update

Привет, я просто прошу слишком много API? Разве невозможно (из коробки) просто вернуть объекты с отношениями один ко многим? Может ли он действительно создать только один список объектов?

Error: User Rate Limit Exceeded

Ваш Ответ

7   ответов
1

Error: User Rate Limit Exceeded

db.tblCustomerBookings.Include("tblRentals").Select(i => 
    new { i.something //etc });

Error: User Rate Limit Exceeded

Error: User Rate Limit ExceededGlobalConfiguration.Configuration.Formatters.RemoveAt(1)Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded Mark
Error: User Rate Limit Exceeded Mark
Error: User Rate Limit Exceeded
1

Error: User Rate Limit ExceededError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded Mark
2

Error: User Rate Limit Exceeded

    public class BookingsController : ApiController
{
    private BookingsContext db = new BookingsContext();

    // GET api/Bookings
    public IEnumerable<tblCustomerBooking> GettblCustomerBookings()
    {
        db.Configuration.ProxyCreationEnabled = false;  
        return db.tblCustomerBookings.AsEnumerable();
    }
}

Error: User Rate Limit Exceededdb

db.Configuration.ProxyCreationEnabled = false;

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

0

Error: User Rate Limit Exceeded

Error: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit Exceeded

UPDATE:

Error: User Rate Limit Exceeded

public IList<tblCustomerBooking> GettblCustomerBookings()
{
    var custBookings = db.tblCustomerBookings.Include("tblRentals").AsEnumerable();

    return custBookings
               .Select(c => new tblCustomerBooking
                            { 
                               customer_id = c.customer_id,
                               customer_name = c.customer_name,
                               customer_email = c.customer_email,
                               tblRentals = c.tblRentals
                                               .Select(r => new tblRentals
                                                      {
                                                          rental_id = r.rental_id,
                                                          // other props exclude the 
                                                          // tblCustomerBooking 
                                                      })
                            }
                      ).ToList();
}

Error: User Rate Limit ExceededJSON.NETError: User Rate Limit Exceeded[JsonIgnore]Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded Mark
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded Mark
Error: User Rate Limit Exceededstrathweb.com/2012/03/…Error: User Rate Limit Exceeded Mark
2

Error: User Rate Limit Exceeded

1, change the action code to include the navigation property data:

    // GET api/Bookings
    public IEnumerable<tblCustomerBooking> GettblCustomerBookings()
    {
        return db.tblCustomerBookings.Include("tblRentals").AsEnumerable();
    }

2, turn off proxy in data context

Error: User Rate Limit Exceeded.

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit ExceededError: User Rate Limit Exceeded.

3, enable preserving reference in model class

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

[JsonObject(IsReference = true)]
[DataContract(IsReference = true)]
public class tblCustomerBooking
{
    [Key()]
    public int customer_id { get; set; }
    [DataMember]
    public string customer_name { get; set; }
    [DataMember]
    public string customer_email { get; set; }
    [DataMember]
    public virtual ICollection<tblRental> tblRentals { get; set; }
}


public class tblRental
{
    [Key()]
    public int rental_id { get; set; }
    public int room_id { get; set; }
    public DateTime check_in { get; set; }
    public DateTime check_out { get; set; }
    public decimal room_cost { get; set; }
    public int customer_id { get; set; }
    [ForeignKey("customer_id")]
    public virtual tblCustomerBooking tblCustomerBooking { get; set; }
}

Error: User Rate Limit Exceeded

0

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

public IEnumerable<tblCustomerBooking> GettblCustomerBookings()
        {
            return db.tblCustomerBookings.Select(cb=> new CustomerBookingsViewModel{id=cb.Id, et.....);
        }

Error: User Rate Limit Exceeded

.Select(cb=>new{id=cb.id....}
0

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded Mark

Похожие вопросы