Here is my method and i would like to cast my return – also i am doing this to prevent from changing my different methods i have and wanted to also know will this have any negative affect if a cast my return?
public VisitEntry Get(Guid visitEntryId)
{
var visitEntry = _visitEntryRepository.Get(visitEntryId);
VisitEntryDTO dto = AutoMapper.Mapper.Map<VisitEntry, VisitEntryDTO>(visitEntry);
dto.CasePartyIds =
_casePartyService.GetAllForHearingEntry(visitEntryId).Select(caseParty => caseParty.CasePartyId).ToList();
return dto;
}
The error i get is for: return dto. Stating: that I cannot converty …Entity.VisitEntryDTO to …Entity.VisitEntry.
any clarification will be great. Thanks!
You likely can’t directly cast from
VisitEntryDTOtoVisitEntry. You’ll need to Automap back.However, your repository seemingly already returns
VisitEntryobjects, so why are you mapping to aVisitEntryDTOin the first place? Why not just do:Unless I’m missing something about your
VisitEntryclass.