OData:Wildcard (startswith) filtering for number (ID) fields in the url request

这一生的挚爱 提交于 2019-12-06 15:08:20

Unfortunately I think you've already discovered one of the best solutions (creating a view). You could also create a service operation that allows you to do fuzzy search.

What are you using for your backend? This isn't supported on LINQ-to-Entities, but you might be able to create a service operation that looks something like this (to prove that it can work, you can stuff a ToList() call in there after Products, just be sure not to deploy something like that to production :)):

[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class ScratchService : DataService<ScratchContext>
{

    [WebGet]
    public IQueryable<Product> FuzzySearch(string idStartsWith)
    {
        var context = new ScratchContext();
        return context.Products.Where(p => p.ID.ToString().StartsWith(idStartsWith));
    }
    // ...
}

It's not an ask we've heard a lot, but I can definitely bring it up on the team and as we start the OASIS standardization process it's something we can be thinking about.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!