错误:
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:无法从用法中推断出方法'System.Threading.Tasks.Task.FromResult(TResult)'的类型参数。尝试显式指定类型参数。
返回 cmsProduct。计数= = 0 错误:当方法“系统”的类型参数时。线程。任务。任务。总是从用法中推断出FromResult(TResult)
代码:
@foreach (var item in cmsProduct)
{
<li>
<h4>@item.CategoryName</h4>
<img src="@url" alt="@item.Title"><span>ProductName</span>
</li>
}
@code {
private IList<dynamic> cmsProduct = new List<dynamic>();
protected override async Task OnParametersSetAsync()
{
cmsProduct = await cmsProductService.GetShowProductList(Id);
}
}
public Task<List<dynamic>> GetShowProductList(string id)
{
using (var scope = _serviceScopeFactory.CreateScope())
{
var context = scope.ServiceProvider.GetService<CmsContext>();
DapperContext dapperContext = new DapperContext(context);
string sql = "SELECT p.Id,p.Title,p.ImgUrl,p.Summary,nm.Url,pc.CategoryName FROM CmsProduct p LEFT JOIN CmsNavMenu nm ON (p.NavMenuId = nm.Id) LEFT JOIN CmsProductCategory pc ON (pc.NavMenuId=nm.Id) where p.Deleted='" + false + "' and p.NavMenuId='" + id + "'";
IEnumerable<dynamic> dynamicResults = dapperContext.Query<dynamic>(sql);
var result = dynamicResults.ToList();
return Task.FromResult(result);
}
}