我正在尝试将Guid传递到用于从数据库返回结果的方法中,但是出现以下错误消息
无法从“ System.Guid?”转换吗?到Abp.Application.Services.Dto.EntityDto
这是两种方法 方法1:
public async Task<ListResultDto<DepartmentDto>> GetAllDepartmentAndReferrerByReferralOrganizationId(EntityDto<Guid> input)
{
var filteredDepartment = _departmentRepository
.GetAll()
.Include(r => r.Referrer)
.Where(a => a.ReferralOrganizationId == input.Id);
var result = await filteredDepartment
.ToListAsync();
var lookupTableDtoList = new List<DepartmentDto>();
//Loop through the department
foreach (var departmentreferrer in result)
{
//Loop through the referrers
foreach (var item in departmentreferrer.Referrer)
{
//get referrer with the id provided
var referrerValue = GetAllReferrers(item.ReferrerId.Value);
lookupTableDtoList.Add(new DepartmentDto
{
Name = $"Department: {departmentreferrer.Name} Referrer: {item.ReferrerId}"
});
}
}
return new ListResultDto<DepartmentDto>(ObjectMapper.Map<List<DepartmentDto>>(lookupTableDtoList));
}
方法2:
public async Task<ListResultDto<GetReferrerForView>> GetAllReferrers(EntityDto<Guid> input)
{
var referrer = _referrerRepository
.GetAll()
.Where(r => r.Id == input.Id);
var result = await referrer
.ToListAsync();
return ObjectMapper.Map<ListResultDto<GetReferrerForView>>(result);
}
问题所在的代码行是我试图将Guid传递给方法的地方,例如GetAllReferrers(item.ReferrerId)。 ReferrerId是可为空的Guid,例如公共虚拟向导? ReferrerId {get;组; }
答案 0 :(得分:0)
您可以像这样实例化EntityDto<Guid>
:
var referrerValue = GetAllReferrers(new EntityDto<Guid>(item.ReferrerId.Value));