正如标题中所描述的那样,我得到了一些类似于list的东西,其中包含了遗忘的字符串列表?
为什么会这样?
这是我的疑问。
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],而不是Full name。
这里有什么问题?
谅谅
你返回的是一个 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);