.Net核心ODataQueryOptions创建错误的实体框架查询

时间:2018-11-16 00:11:42

标签: entity-framework .net-core odata

当我使用AllowedQueryOptions调用ApplyTo方法时,执行的所有查询都没有任何top / orderby线索。如果删除了AllowedQueryOptions参数查询将执行效率更高的数据库查询。不幸的是,我必须对顶部使用AllowedQueryOptions并跳过才能正常工作。解决此问题的任何想法。

带有AllowedQueryOptions.All

 var settings = new ODataQuerySettings();
 IQueryable<Asset> events = options.ApplyTo(data, settings, AllowedQueryOptions.All) as IQueryable<Asset>;

 SELECT [a].[Id], [a].[Name],[a].[UniqueCode]
      FROM [Asset] AS [a]
      WHERE [a].[AssetId] = @__id_0

没有AllowedQueryOptions.All

var settings = new ODataQuerySettings();
IQueryable<Asset> events = options.ApplyTo(data, settings) as IQueryable<Asset>;

SELECT TOP(@__TypedProperty_1) [a].[Id], [a].[Name],[a].[UniqueCode]
      FROM [Asset] AS [a]
      WHERE [a].[AssetId] = @__id_0
      ORDER BY [a].[Name] DESC, [a].[Id]

0 个答案:

没有答案