有没有办法通过指定"日期大于xxxxx"过滤器来返回OData中的一系列记录...但是使用之前从OData Feed获得的日期?
使用案例:假设我想构建一个显示最近完成的在线订单列表的网页.这就是我的目标:
我正在努力的是指定日期"大于"过滤器.出于某种原因,OData中的日期过滤器似乎与OData自己的本机日期格式不太匹配.我是否需要将最初获得的日期转换为可用于过滤的其他格式?
我想做这样的事情:
[http://mydomain/Services/v001.svc/Orders?$filter=close_dt gt 1338336000000][1]
Run Code Online (Sandbox Code Playgroud)
仅供参考:我正在使用V2
在性能,开发人员可用性,社区等方面,GraphQL和OData是否有很好的比较.我在互联网上找到的所有文章都非常偏向.
返回大型JSON或二进制数据的最佳方法是什么?
如果我的模型中有两个实体,"People"和"Addresses",并且一个特定Person有零个或多个地址,通过AddressList导航属性访问,我可以编写一个OData查询来回答以下问题:
"哪个人的姓氏以史密斯结尾,至少有一个地址?"
在我看来,我只能在这里做一个谓词,例如
http:// localhost:55100/DemographicsDataService.svc/People?$ filter = endswith(LastName,'Smith')
(我还不相信我甚至可以写一个$ filter来处理第二个谓词..在这种情况下,假设我试图回答这个问题,"姓氏以史密斯结尾,名字以玛丽开头")
在将OData添加到我的项目之前,我的路由设置如下:
config.Routes.MapHttpRoute(
name: "ApiById",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional },
constraints: new { id = @"^[0-9]+$" },
handler: sessionHandler
);
config.Routes.MapHttpRoute(
name: "ApiByAction",
routeTemplate: "api/{controller}/{action}",
defaults: new { action = "Get" },
constraints: null,
handler: sessionHandler
);
config.Routes.MapHttpRoute(
name: "ApiByIdAction",
routeTemplate: "api/{controller}/{id}/{action}",
defaults: new { id = RouteParameter.Optional },
constraints: new { id = @"^[0-9]+$" },
handler: sessionHandler
Run Code Online (Sandbox Code Playgroud)
所有控制器都提供Get,Put(操作名称为Create),Patch(操作名称为Update)和Delete.例如,客户端使用这些各种标准URL来表示CustomerType请求:
string getUrl = "api/CustomerType/{0}";
string findUrl = "api/CustomerType/Find?param={0}";
string createUrl = "api/CustomerType/Create";
string updateUrl = "api/CustomerType/Update";
string deleteUrl …
Run Code Online (Sandbox Code Playgroud) 我熟悉Microsoft堆栈.我正在使用OData来完成我的一些宁静服务.最近我遇到了Swagger的API文档,我试图了解它与OData的关系.它们似乎都是RESTful规范.哪一个被广泛使用?
我刚刚看到ServiceStack,我正在考虑用它来构建服务.
是否可以使用服务堆栈提供OData提要,以便我能够公开IQueryable并从客户端查询它?
我正在使用OData来查询我的数据库.当"adapterName"只包含文本时,以下代码行正常工作.
ds.query('/DataAdapters?$filter=Name eq \'' + adapterName + '\'', ifmgr_CreateAdapter_Step1, onGenericFailure, '');
Run Code Online (Sandbox Code Playgroud)
如果"adapterName"包含单引号则失败.我尝试使用以下代码转义单引号:
adapterName = adapterName.replace(/\'/g, '\\\'');
Run Code Online (Sandbox Code Playgroud)
虽然这正确地逃避了用户定义的文本,但该功能仍然失败.谁能告诉我查询中文本的正确格式是什么?
我知道ODATA可以返回json但不确定我是否必须使用属性或接口来执行此操作.
我希望它像http://odata.netflix.com/Catalog/Titles?$ format = JSON一样,但我的odata服务不返回JSON.当我把它称为www.foo.com/service?$format=json时,它只返回XML.
使用ODATA返回json需要做什么?
我正在尝试创建一个MediaTypeFormatter
处理text/csv
但$expand
在OData查询中使用时遇到一些问题.
查询:
http://localhost/RestBlog/api/Blogs/121?$expand=Comments
Run Code Online (Sandbox Code Playgroud)
控制器:
[EnableQuery]
public IQueryable<Blog> GetBlog(int id)
{
return DbCtx.Blog.Where(x => x.blogID == id);
}
Run Code Online (Sandbox Code Playgroud)
在我的媒体类型格式化程序中:
private static MethodInfo _createStreamWriter =
typeof(CsvFormatter)
.GetMethods(BindingFlags.Static | BindingFlags.NonPublic)
.Single(m => m.Name == "StreamWriter");
internal static void StreamWriter<T, X>(T results)
{
var queryableResult = results as IQueryable<X>;
if (queryableResult != null)
{
var actualResults = queryableResult.ToList<X>();
}
}
public override void WriteToStream(Type type, object value,
Stream writeStream, HttpContent content)
{
Type genericType = type.GetGenericArguments()[0];
_createStreamWriter.MakeGenericMethod(
new …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用OData和EntityFramework创建一个带有"简单"web api的新ASP.NET Core项目.我之前使用OData与旧版本的ASP.NET.
我已经设置了一个只有一个简单的get函数的控制器.我已经设法使用基本的OData命令作为过滤器和顶部,但我无法使扩展命令工作.我想这是因为我无法弄清楚如何在Startup.cs中设置它.我尝试过很多东西,包括跟随Github的一些odata样本:
https://github.com/OData/WebApi/tree/vNext/vNext/samples/ODataSample.Web https://github.com/bigfont/WebApi/tree/master/vNext/samples/ODataSample.Web
在我的启动文件中,我尝试从Service类中排除一些根本没有效果的属性.所以问题可能在于我使用IDataService接口的方式.(ApplicationContext像样本一样实现它)
要明确我正在使用完整的.NET Framework创建一个ASP.NET Core web api,而不仅仅是.Core框架.我当前的代码是两个样本中最好/最差的混合,并且我可以过滤WebAPI,但不能让它扩展或隐藏属性.
任何人都可以看到我缺少的东西og有一个工作的ASP.NET Odata样本.我是startup.cs中整个设置的新手?猜猜我正在找一个做过这项工作的人.
调节器
[EnableQuery]
[Route("odata/Services")]
public class ServicesController : Controller
{
private IGenericRepository<Service> _serviceRepo;
private IUnitOfWork _unitOfWork;
public ServicesController(IGenericRepository<Service> serviceRepo, IUnitOfWork unitOfWork)
{
_serviceRepo = serviceRepo;
_unitOfWork = unitOfWork;
}
[HttpGet]
public IQueryable<Service> Get()
{
var services = _serviceRepo.AsQueryable();
return services;
}
}
Run Code Online (Sandbox Code Playgroud)
启动
using Core.DomainModel;
using Core.DomainServices;
using Infrastructure.DataAccess;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.OData.Extensions;
namespace Web
{
public class Startup …
Run Code Online (Sandbox Code Playgroud) c# odata asp.net-web-api-odata asp.net-core asp.net-core-webapi
odata ×10
c# ×5
asp.net-core ×1
filter ×1
graphql ×1
json ×1
linq ×1
openapi ×1
predicate ×1
servicestack ×1
swagger ×1
swashbuckle ×1
wcf ×1