C#Dapper-在QueryAsync方法上使用linq [英] c# Dapper - using linq on QueryAsync method
问题描述
当在queryAsync上正常工作时,为什么不能在queryAsync上使用.select?
例如,在这里.select对我大吼,告诉我它无法解析符号 select:
Why can't I use .select on a queryAsync when it works fine on Query? For example, here the .select yells at me telling me it cant resolve the symbol "select":
var result = await sqlConnection.QueryAsync<Product>(procedure,
commandType: CommandType.StoredProcedure).Select(p => new Product
{
Code= (string)p.fldCode,
Name=(string)p.fldName
});
但是一旦我更改为Query,它就不会再大喊大叫了。如果有问题,则无法从sp中解析fldCode列:
but as soon as i change to Query, it doesn't yell anymore. if anything it has trouble resolving the fldCode columns from the sp:
var result = sqlConnection.Query<Product>(procedure,
commandType: CommandType.StoredProcedure).Select(p => new Product
{
Code= (string)p.fldCode,
Name=(string)p.fldName
});
这是为什么?
我在这里问了一个先前的问题将C#Dapper映射列映射到实体属性-无法解析符号'Select''
I asked a previous question here C# Dapper mapping columns to entity properties - "Cannot resolve symbol 'Select'"
推荐答案
异步方法返回Task(基本上是占位符的最终结果)异步操作)。您需要等待它以获取实际值
Async methods return a Task (basically a placeholder for the eventual result of the async action). You need to await it to get the actual value
var result = (await sqlConnection.QueryAsync<Product>(
procedure,
commandType: CommandType.StoredProcedure
)).Select(p => new Product
{
Code= (string)p.fldCode,
Name=(string)p.fldName
}
);
这篇关于C#Dapper-在QueryAsync方法上使用linq的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!