Always have error “The ObjectContent 1 type failed to serialize the response body…”

后端 未结 4 491
再見小時候
再見小時候 2021-01-02 11:03

I use Web api to retrieve data from the database. I only have 1 table \"tblMessage\" and want to get data from that table.

I set everything up but then when I run th

4条回答
  •  梦谈多话
    2021-01-02 12:01

    I had the same problem and this is the solution I found

    After updating the Entity Data Model you have to set ProxyCreationEnabled to false in your Model

    Configuration.ProxyCreationEnabled = false;

    My example:

    public partial class EventsEntities : DbContext
    {
            public EventsEntities()
                : base("name=EventsEntities")
            {
                Configuration.ProxyCreationEnabled = false;
            }
            protected override void OnModelCreating(DbModelBuilder modelBuilder)
            {
                throw new UnintentionalCodeFirstException();
            }
    }
    

提交回复
热议问题