C# LINQ - 道具字符串的值为 System.Collections.Generic.List`1[System.String]

C# LINQ - Prop string has value of System.Collections.Generic.List`1[System.String]

正如标题中所述,我越来越像列表,其中包含明显的字符串列表?

怎么会?

这是我的查询:

var productChangesUpdate = await _dbContext.ProductUpdates.Where(x => x.ProductId == ProductId)
                          .Select(x => new ProductChangeDto
                          {
                              Id = x.Id,
                              Title = x.Title,
                              Price = x.Price,
                              Date = x.CreatedDate,
                              ResponsiblePerson = x.ProductDeploy.ProductDeployResponsiblePersons.Select(x => x.User.FirstName + x.User.LastName).ToString()
                          }).ToListAsync(cancellationToken);

问题是 ResponsiblePerson 值是 System.Collections.Generic.List`1[System.String] 而不是全名..

这是怎么回事?

谢谢

您正在返回一个 List. 您必须在您的案例中使用类似于 FirstOrDefaultAsync() 或 SingleOrDefaultAsync() 的东西。

var productChangesUpdate = await _dbContext.ProductUpdates.Where(x => x.ProductId == ProductId)
                          .Select(x => new ProductChangeDto
                          {
                              Id = x.Id,
                              Title = x.Title,
                              Price = x.Price,
                              Date = x.CreatedDate,
                              ResponsiblePerson = x.ProductDeploy.ProductDeployResponsiblePersons.Select(x => x.User.FirstName + x.User.LastName).ToString()
                          }).FirstOrDefaultAsync(cancellationToken);