[英]OData service Out of memory exception
I have an OData service build under Web Api V2. 我在Web Api V2下有一个OData服务版本。 I have a controller with a Linq query to return the data from a table. 我有一个带有Linq查询的控制器,用于从表中返回数据。 This is the controller query: 这是控制器查询:
[EnableQuery]
public IQueryable<ImportContracts_ImportContracts> Get()
{
IQueryable<ImportContracts_ImportContracts> query = new List<ImportContracts_ImportContracts>().AsQueryable();
query = (from BRRIMPORTCONTRACTS imcon in db.BRRIMPORTCONTRACTS.Where(x => x.ZZSTATE == 0)
select new
{
ReferenceDateData = imcon.ReferenceDate,
ImportationDate = imcon.ImportationDate,
LastImportation = imcon.LastImportation
}).ToList().Select(x => new ImportContracts_ImportContracts
{
ReferenceDateData = x.ReferenceDateData,
ImportationDate = x.ImportationDate,
LastImportation = x.LastImportation
}).AsQueryable();
return query;
}
My table BRRMIMPORTCONTRACTS have 1million records. 我的表BRRMIMPORTCONTRACTS有100万条记录。 When I get here, I get an System.OutOfMemoryException. 当我到达这里时,我得到一个System.OutOfMemoryException。
I know maybe this isn't the best way to query the entity but I just want a workaround for this. 我知道这可能不是查询实体的最佳方法,但我只是想要一种解决方法。
I've tried [EnableQuery(PageSize=10)] hint but with no success. 我尝试了[EnableQuery(PageSize = 10)]提示,但没有成功。 I think the problem is in the query itself. 我认为问题出在查询本身。
Thanks in advance. 提前致谢。 Filipe 菲利普
Does this make a difference? 这有什么不同吗?
[EnableQuery]
public IQueryable<ImportContracts_ImportContracts> Get()
{
IQueryable<ImportContracts_ImportContracts> query = new List<ImportContracts_ImportContracts>().AsQueryable();
query = (from BRRIMPORTCONTRACTS imcon in db.BRRIMPORTCONTRACTS.Where(x => x.ZZSTATE == 0)
.Select(x => new ImportContracts_ImportContracts
{
ReferenceDateData = x.ReferenceDate,
ImportationDate = x.ImportationDate,
LastImportation = x.LastImportation
});
return query;
}
Note that your ToList() is gone, so an IQueryable is returned. 请注意,您的ToList()已消失,因此返回了IQueryable。 Does that help? 有帮助吗?
Can you apply the query by yourself, for example 例如,您可以自己应用查询吗?
public IQueryable<ImportContracts_ImportContracts> Get(ODataQueryOptions<..> options)
{
IQueryable<ImportContracts_ImportContracts> query = new List<ImportContracts_ImportContracts>().AsQueryable();
// use the options to apply
...
return query;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.