从复杂对象中过滤 ASP.NET MVC JsonResult 中的 Json
我试图从数据模型中的复杂对象(Json)发布,不幸的是,我不想传递所有层次结构(人->HasMany Orders/ Orders HasMany Products 等),而只想传递“第一级”(例如网格视图的人名)。
public JsonResult Search(string fMname, string fSname)
{
IList<Person> people = personRepository.FindAllMatchingName(fMname, fSname);
//Here with lazy loading querying only the “first level” for object
var data = people;
return Json(new { items = data });
//Here querying full object hierarchy and return the big Json
}
我正在寻找一种解决方案来过滤 Json 对象,并且——如果可能的话——进行延迟加载并避免 sql 开销。
有什么想法吗?
I am trying to post from a complex object from data model, a Json, unfortunately, I don’t want to pass all the hierarchy (person->HasMany Orders/ Orders HasMany Products etc.) but only the “first level” (for example person names for a grid view).
public JsonResult Search(string fMname, string fSname)
{
IList<Person> people = personRepository.FindAllMatchingName(fMname, fSname);
//Here with lazy loading querying only the “first level” for object
var data = people;
return Json(new { items = data });
//Here querying full object hierarchy and return the big Json
}
I am looking for a solution to filter the Json object and – if this is possible – to work the lazy loading and to avoid the sql overhead.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建一个简化的人员类,仅包含您需要的属性。然后使用Linq将Person的IList转换为简化类型的列表。
您可以改用匿名类型,但它不会在视图中强类型化。
Create a simplified person class that only contains the properties you need. Then transform the IList of Person into a list of the simplified type using Linq.
You could use an anonymous type instead, but it wouldn't be strongly typed in the view.