对不起,如果这是一个愚蠢的问题,但我是 LINQ 的新手。我有一个使用 Dapper 使用 async/await 逻辑查询数据库的服务。服务中的方法我可以在 linq 中使用 SELECT 但在控制器中此选项不允许我使用?我只有“ToSelectListItems”而不是 SELECT ..我在这里错过了什么?
服务:
public async Task<IEnumerable<AwardWinResult>> GetAwardWinnersAsync(bool useCache = true)
{
var data = await awardWinnersRepository.GetWinnersAsync();
return data;;
}
控制器:
public async Task<ActionResult> Index()
{
var awardWinners = await awardWinnersService.GetAwardWinnersAsync();
var viewModel = new AwardWinnersWrapperVM
{
AwardWinners = await awardWinners.SelectMissingHere?(x => new AwardWinnersViewModel
{
AwardId = x.AwardId
})
};
return View(awardWinners);
}
存储库:
public async Task<IEnumerable<AwardWinResult>> GetWinnersAsync()
{
using (var conn = new System.Data.SqlClient.SqlConnection(Proj.DataContext.ConnectionString))
{
await conn.OpenAsync();
var data = await conn.QueryAsync<AwardWinResult>(@"
SELECT aw.[WinnerId], aw.[AwardId], aw.[AwardCategoryId] as CategoryId, a.[Name] as AwardName, ac.[Name] as CategoryName, a.[StartDate], a.[EndDate], a.[LaunchDate]
FROM [Proj].[AwardWinners] aw
LEFT JOIN [Proj].[AwardCategories] ac on aw.AwardCategoryId = ac.Id
LEFT JOIN [Proj].[Awards] a on aw.AwardId = a.Id
LEFT JOIN [Proj].[AwardJurisdictionGroups] ajg on ac.[JurisdictionGroupId] = ajg.[Id]
LEFT JOIN [Proj].[AwardWorkareaGroups] awg on ac.[WorkareaGroupId] = awg.[Id]
");
return data.ToList();
}
}
摇曳的蔷薇
相关分类