【发布时间】:2014-10-09 14:03:57
【问题描述】:
我在 MVC 5 应用程序中使用 ADO.net 作为我的 ORM 工具,问题是:
- 当我对我的 web api 执行一些 POST 操作并返回一些数据时,在我的响应中 JSON 包含来自外键的所有值,但我没有包含一些数据。
看看这条简单的线:
public async Task<IHttpActionResult> GetMyMessage(int id)
{
List<Messages> messages = await db.Messages.Where(a => a.GroupID == id).ToListAsync();
return Ok(messages);
}
问题出在这里,我没有在我的消息中包含任何数据(例如 db.Messages.Include(something...)),但作为响应,我得到了所有用户集合以及我的消息表中的其他内容在 DB 中连接。
我的全局 asax 是:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
}
有谁知道如何摆脱这个链接表并获得干净的 json 响应。否则我将不得不做一些解决方法并稍微清理一下。 ?
【问题讨论】:
标签: c# asp.net asp.net-mvc json asp.net-web-api