【发布时间】:2019-03-20 01:02:26
【问题描述】:
我定义了一个 odata 函数来模拟最近的核心版本中尚不支持的 $search。我想返回核心实体加上一个扩展实体,该实体将在返回的 json 值数组中的每个 Person 上转换为一个 js 对象。
我尝试了 odata/People/MyNS.Find(text='john', orderby='CreatedOn')?$expand=CurrentWork,其中 CurrentWork 在 People 上,但没有奏效。
关于如何做到这一点的想法?
// my controller code for the function
[HttpGet]
public ActionResult<ICollection<People>> Find([FromODataUri] string text,
[FromODataUri] string orderBy)
{
if (text == null || text.Length == 0)
return Get().ToList();
if (orderBy == null || orderBy.Length == 0)
orderBy = "CreatedOn";
return _db.People
.Where(p => p.FirstName.Contains(text)
|| p.LastName.Contains(text)
|| p.Nickname.Contains(text))
.OrderBy(orderBy)
.Take(5000)
.ToList();
}
CurrentWork 在非函数中的常规扩展工作正常,例如odata/People?$expand=CurrentWork.
【问题讨论】:
标签: asp.net-web-api asp.net-core odata