- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们使用带有 OData 和 Dapper 作为 ORM 的 ASP.Net Webapi。对于 GET 请求,我们分别使用选项参数对象和它的过滤器参数来为 Dapper 查询构建 SQL 字符串。这适用于列 eq 值等。
但现在我想做一些服务器端分页。这意味着我使用两个过滤器($top 和 $skip)发出请求。例如。 "https://api.server.com/Orders ?$skip=100&$top=50。Dapper 向数据库发出正确的请求,我得到一个包含 50 个条目的结果作为来自 dapper 的响应。
然后我将此结果放入 webapi Controller 的返回语句中,webapi 似乎自行进行过滤。因此它执行从 50 的结果中跳过 100,这导致 0 个条目。
有没有人遇到同样的问题并找到了一种方法来阻止 webapi 过滤但将过滤委托(delegate)给 ORM?编写 ApiControllers 而不是 ODataControllers 是别无选择,因为我真的很喜欢使用 odata 语法进行过滤。
感谢您的回答!
最佳答案
假设您的 API 操作的返回类型是 IQueryable,那么框架将对从数据库返回的任何数据应用查询过滤器,因此让我们将查询结果包装到 PageResult 中并返回它,它不会再次应用过滤器.示例代码如下-
public PageResult<Orders> GetOrdersPage(ODataQueryOptions<Orders> queryOptions)
{
// Parse queryOptions to get Top and Skip
var top = queryOptions.Top.RawValue;
var skip = queryOptions.Skip.RawValue;
//Call the dataaccess method and then get Querable result
var queryResults = dataAccess.GetOrders(top,skip).AsQuerable<Orders>();
//Return Page result
return new PageResult<Orders>(queryResults, new URI("Next page URI"), 1234); //1234 - is total count of records in table
}
关于c# - 带有 Odata-V4 和 Dapper 的 Web Api - 服务器端过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35696996/
有谁知道或有如何使用的链接https://github.com/henkmollema/Dapper-FluentMap在我的 Dapper CRUD 中?现在我正在使用 Dapper.Contrib
我正在寻找一种方法来仅更新 Dapper 中的设置属性。即仅当实体的属性不为空时才更新实体的属性。 我正在用一种相当粗糙的方法解决同样的问题,如下所示,但我相信应该有一种更简洁的方法来做到这一点。
方案: 我的模型中有一个字符串属性,其中包含MultiSelectList @Html.ListBox的ID。如果选择两个列表项,则我的属性值将类似于0100,0500。 问题: Dapper whe
我们正在使用 Dapper 进行一些数据访问事件,并使用标准推荐方法连接到数据库,如下所示: public static Func ConnectionFactory = () => new SqlC
是否可以通过表名 作为 Dapper Query 命令的参数?我不是在寻找 SQL 表定义的函数或 SQL 表变量。我想在 C# 中定义表名并将其传递给 Dapper。这是我的代码,执行时返回错误 M
我在dapper中尝试对包含NULL的列进行拆分时遇到MultiMaps问题。 Dapper似乎不实例化对象,并且我的映射函数接收null而不是对象。 这是我的新测试: class Produ
我似乎找不到我的问题的文档或示例(现在已经搜索了一段时间)。我认为我的问题很简单,所以这里是。 我有两张 table 。我的主表称为 Persons,辅助表是 PersonEntries。对于 Per
我的代码有点问题,我想让 dapper 很好地使用它。 当我说我的代码是继承的,所以这不是我的设计。 我正在尝试替换 Entity Framework,因为对数据库的调用效率不高,所以我想更好地控制生
我已经开始玩 Dapper.Net,到目前为止我真的很喜欢它 - 然而,我遇到了一个问题。 假设我有一个 POCO 类: public class Person { public string
我已经开始玩 Dapper.Net,到目前为止我真的很喜欢它 - 然而,我遇到了一个问题。 假设我有一个 POCO 类: public class Person { public string
我知道这是一种错误的做法,但我正在处理具有 NULLS 的遗留代码库,当它表示空字符串时,反之亦然。 我无法立即看到它是如何可能的,但是当从数据库映射回来时,是否有可能获取(或修改 dapper 以便
我正在尝试选择一个包含 2 个整数列的列表,将结果映射到一个元组。举个例子: return connection.Query>("select id1, id2 from sometable").To
我有一个存储过程,它有一个没有默认值的参数,但它可以为空。但我不知道如何使用 Dapper 传递 null。我可以在 ADO 中做得很好。 connection.Execute("spLMS_Upda
我决定使用 Dapper.net,因为它似乎只做我想做的事情:映射,我不需要任何花哨的东西,我只是厌倦了处理我的数据读取器和我的对象之间的映射。 我的问题: 假设我有这些类(class): class
我在从 Dapper 查询返回单个对象时遇到问题。我有一个简单的查询,我想从返回的集合中获取第一个对象。我错过了什么? using (SqlConnection sqlConnection = new
假设我的实体是 public class AppUser { string Id { get; set; } string Name { get; set; } } 看起来默认情况下
我在Dapper官方文档中看到了QueryMultiple,如下所示,很方便! var sql = @" select * from Customers where CustomerId =
我正在使用 Dapper 查询包含 XML 字段的表: CREATE TABLE Workflow ( Guid uniqueidentifier not null, State xm
我有一个来自Dapper查询的动态结果,其中包含如下记录: {DapperRow, billing_currency_code = 'USD', count(*) = '6'} 我可以使用rowVar
我正在使用 Dapper 扩展,但我的数据库中有多个架构名称。 我在下面的链接中找到了答案,但它假设我只有一个模式名称,这不是我的情况。 Dapper Extensions Change Schema
我是一名优秀的程序员,十分优秀!