Api <;例外类型>;System.Runtime.Serialization.SerializationException

Api <;例外类型>;System.Runtime.Serialization.SerializationException,api,asp.net-web-api,Api,Asp.net Web Api,当我将控制器添加到(get、put、post、delete)时,我得到了相同的错误 控制器代码为 using System; using System.Collections.Generic; using System.Data; using System.Data.Entity; using System.Data.Entity.Infrastructure; using System.Linq; using System.Net; using System.Net.Http; using

当我将控制器添加到(get、put、post、delete)时,我得到了相同的错误

控制器代码为

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

namespace YourRealityAPI.Controllers
{
    public class T_UsersController : ApiController
    {
        private YourRealityDBEntities db = new YourRealityDBEntities();

        // GET: api/T_Users
        public IQueryable<T_Users> GetT_Users()
        {
            return db.T_Users;
        }

        // GET: api/T_Users/5
        [ResponseType(typeof(T_Users))]
        public IHttpActionResult GetT_Users(int id)
        {
            T_Users t_Users = db.T_Users.Find(id);
            if (t_Users == null)
            {
                return NotFound();
            }

            return Ok(t_Users);
        }

        // PUT: api/T_Users/5
        [ResponseType(typeof(void))]
        public IHttpActionResult PutT_Users(int id, T_Users t_Users)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != t_Users.U_id)
            {
                return BadRequest();
            }

            db.Entry(t_Users).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!T_UsersExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }

        // POST: api/T_Users
        [ResponseType(typeof(T_Users))]
        public IHttpActionResult PostT_Users(T_Users t_Users)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.T_Users.Add(t_Users);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = t_Users.U_id }, t_Users);
        }

        // DELETE: api/T_Users/5
        [ResponseType(typeof(T_Users))]
        public IHttpActionResult DeleteT_Users(int id)
        {
            T_Users t_Users = db.T_Users.Find(id);
            if (t_Users == null)
            {
                return NotFound();
            }

            db.T_Users.Remove(t_Users);
            db.SaveChanges();

            return Ok(t_Users);
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                db.Dispose();
            }
            base.Dispose(disposing);
        }

        private bool T_UsersExists(int id)
        {
            return db.T_Users.Count(e => e.U_id == id) > 0;
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用系统数据;
使用System.Data.Entity;
使用System.Data.Entity.Infrastructure;
使用System.Linq;
Net系统;
使用System.Net.Http;
使用System.Web.Http;
使用System.Web.Http.Description;
使用RealityAPI.Models;
命名空间YourRealityAPI.Controllers
{
公共类T_用户控制器:ApiController
{
private yourrealitydbenties db=new yourrealitydbenties();
//获取:api/T_用户
公共IQueryable GetT_用户()
{
返回db.T_用户;
}
//获取:api/T_用户/5
[响应类型(类型(T_用户))]
公共IHttpActionResult GetT_用户(int id)
{
T_Users T_Users=db.T_Users.Find(id);
if(t_Users==null)
{
返回NotFound();
}
返回Ok(t_用户);
}
//PUT:api/T_Users/5
[响应类型(typeof(void))]
公共IHttpActionResult PutT_用户(int-id、T_用户T_用户)
{
如果(!ModelState.IsValid)
{
返回请求(ModelState);
}
if(id!=t_Users.U_id)
{
返回请求();
}
db.Entry(t_Users).State=EntityState.Modified;
尝试
{
db.SaveChanges();
}
catch(DbUpdateConcurrencyException)
{
如果(!T_用户性别歧视者(id))
{
返回NotFound();
}
其他的
{
投掷;
}
}
返回状态码(HttpStatusCode.NoContent);
}
//职位:api/T_用户
[响应类型(类型(T_用户))]
公共IHttpActionResult PostT_用户(T_用户T_用户)
{
如果(!ModelState.IsValid)
{
返回请求(ModelState);
}
db.T_Users.Add(T_Users);
db.SaveChanges();
返回CreatedAtRoute(“DefaultApi”,新的{id=t_Users.U_id},t_Users);
}
//删除:api/T_用户/5
[响应类型(类型(T_用户))]
公共IHttpActionResult DELETE_用户(内部id)
{
T_Users T_Users=db.T_Users.Find(id);
if(t_Users==null)
{
返回NotFound();
}
db.T_Users.Remove(T_Users);
db.SaveChanges();
返回Ok(t_用户);
}
受保护的覆盖无效处置(布尔处置)
{
如果(处置)
{
db.Dispose();
}
基地。处置(处置);
}
私人bool T_用户性别歧视者(int-id)
{
返回db.T_Users.Count(e=>e.U_id==id)>0;
}
}
}
数据库名称“T_Users”类(T_Users.cs)中的表是

//------------------------------------------------------------------------------
//

我怎么能(获取、放置、发布、删除)和我在每个方面都有相同的错误呢 有什么问题,我该怎么做

    //------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated from a template.
//
//     Manual changes to this file may cause unexpected behavior in your application.
//     Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace YourRealityAPI.Models
{
    using System;
    using System.Collections.Generic;

    public partial class T_Users
    {
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
        public T_Users()
        {
            this.T_Clients = new HashSet<T_Clients>();
            this.T_Projects = new HashSet<T_Projects>();
        }

        public int U_id { get; set; }
        public string U_username { get; set; }
        public string U_password { get; set; }
        public Nullable<System.DateTime> U_CreationDate { get; set; }
        public Nullable<int> U_type { get; set; }
        public Nullable<bool> U_isBanned { get; set; }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
        public virtual ICollection<T_Clients> T_Clients { get; set; }
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
        public virtual ICollection<T_Projects> T_Projects { get; set; }
        public virtual T_UserType T_UserType { get; set; }
    }
}