简体   繁体   English

在Dapper中,功能是什么 <TFirst, TSecond, TReturn> map方法参数看起来像。 有没有可以看的测试用例?

[英]In Dapper, what does the Func<TFirst, TSecond, TReturn> map method parameter looks like. Is there a test case that I can look at?

I have been trying to implement the below dapper method call. 我一直在尝试实现以下dapper方法调用。 I do not know what is the expectation for the method parameter: 我不知道对方法参数的期望是什么:

Func<TFirst, TSecond, TReturn> map

for this Dapper call: 对于此Dapper调用:

Task<IEnumerable<TReturn>> QueryAsync<TFirst, TSecond, TReturn>(string sql, Func<TFirst, TSecond, TReturn> map, dynamic param = null, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = default(int?), CommandType? commandType = default(CommandType?))

Is there a test case that I can take a look at? 有没有可以看的测试用例? I have not found one yet. 我还没有找到。

Let's understand in little detail from the signature provided. 让我们从提供的签名中详细了解一下。 Firstly this looks like an overload, otherwise the QueryAsync works in same way as Query, just that its Asynchronous. 首先,这看起来像是一个重载,否则QueryAsync的工作方式与Query相同,只是异步的。 This would have made more sense for QueryMultiple 这对于QueryMultiple更有意义

Important parts are: 重要部分是:

QueryAsync<TFirst, TSecond, TReturn> - Signature QueryAsync<TFirst, TSecond, TReturn> -签名

Func<TFirst, TSecond, TReturn> map - Usage of Signature Func<TFirst, TSecond, TReturn> map -签名的用法

Usage of Signature 签名使用

Task<IEnumerable<TReturn>> - Return Type Task<IEnumerable<TReturn>> -返回类型

Now since you are executing the Query , not QueryMultiple , so the return of the Sql Execution would be only single type, I assume TReturn , what Func delegate would do is, do some processing of the result, which you need to do by supplying the logic, something like, where TFirst and TSecond become integer types, it could be any type of your choice: 现在,由于您正在执行Query而不是QueryMultiple ,因此Sql Execution的返回将仅为单一类型,我假设TReturn ,Func委托将要做的是,对结果进行一些处理,这需要通过提供逻辑,例如TFirst和TSecond变为整数类型,它可以是您选择的任何类型:

Func<int,int,TReturn> func = (a,b) => { use a,b values to filter the values in IEnumerable<Treturn> fetched and return the same }

I must admit that I am little confused though, since for doing anything inside the QueryAsync function means unwrapping the Task , which is returned from the Async function. 我必须承认我有点困惑,因为在QueryAsync函数中执行任何操作都意味着解包Task ,这是从Async函数返回的。 Better solution here shall be: 更好的解决方案是:

Run QueryAsync as is: 按原样运行QueryAsync:

Task<IEnumerable<TReturn>> QueryAsync<TReturn>(string sql, dynamic param = null, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = default(int?), CommandType? commandType = default(CommandType?))

var result = connection.QueryAsync<TReturn>(sql).Result; // Making this as a blocking call just for example //例如,将此作为阻止调用

Now apply the Func to transform the values inside IEnumerable<TReturn> 现在应用Func转换IEnumerable<TReturn>的值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 方法&#39;Enumerable.Zip的类型参数 <TFirst, TSecond, TResult> (IEnumerable的 <TFirst> ,IEnumerable <TSecond> ,Func - The type arguments for method 'Enumerable.Zip<TFirst, TSecond, TResult>(IEnumerable<TFirst>, IEnumerable<TSecond>, Func<TFirst, 这个 Func 中的第一个箭头运算符是什么<t, treturn>意思是?</t,> - What does the first arrow operator in this Func<T, TReturn> mean? 如何使用邮编<TFirst,TSecond> (IEnumerable<TFirst> , IEnumerable<TSecond> )? - How to use Zip<TFirst,TSecond>(IEnumerable<TFirst>, IEnumerable<TSecond>)? “第一个”异步方法是什么样的? - What does “the first” async method look like? tostring 方法的单元测试应该是什么样的? - What should a unit test for a tostring method look like? 如何获取作为 func 传递的匿名方法的参数值? - How can i get the parameter values of an anonymous method passed as a func? 如何在运行时查看winform的外观? - How can I see what a winform looks like at runtime? 在IL中看起来像什么? - What does an if look like in IL? 我可以从 Dapper DynamicParameters 中删除参数吗? - Can I remove a parameter from the Dapper DynamicParameters? 如何将 Dapper QueryFirst 映射到类? - How can I map a Dapper QueryFirst to a class?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM