api - System.Runtime.Serialization.SerializationException
问题描述
当我将控制器添加到(获取、放置、发布、删除)时,我得到了同样的错误 在此处输入图像描述
控制器代码是
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;
}
}
}
并且数据库名称“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; }
}
}
当我尝试运行项目 API 并遇到此问题时,请 在此处输入图像描述
我怎么能(get,put,post,delete)并且我在每一个中都有相同的错误是什么问题,我该怎么做
解决方案
推荐阅读
- svn - 在现有主干中解耦大小代码并使用当前代码创建新主干的最佳方法
- xslt - XSL 转换返回空白值
- python - 根据第二列的值在 csv 中选择一个项目
- reactjs - 无法使用 graphQL 和 createPages 在 Gatsby 中进行转换
- python - 如何使用 GridSearchCV 获取所有模型(每组参数一个)?
- python - 无法连接使用 Channels (Django) 与多个浏览器进行 websocket 通信(无法接收消息)
- php - Laravel 没有完成多个请求的控制器方法
- android - 谷歌地图崩溃和内存使用
- php - 从数据库中获取选择选项并将选择的选项传递给 PHP 变量
- xamarin.forms.listview - 删除 xamarin 表单中列表视图的空白空间