E
E
embiid2021-03-15 22:44:45
ASP.NET
embiid, 2021-03-15 22:44:45

How to convert from one type to another?

And here is its interface implementation:

public async Task<ProductDto> AddAsync(ProductDto item)
        {
            var product = await _unitOfWork.ProductRepository.AddAsync(item);
            return _mapper.Map<ProductDto>(product);
        }


And here is what is in unitofwork:
public async Task<Product> AddAsync(Product id)
        {
            _context.Set<Product>().Add(id);
            await _context.SaveChangesAsync();

            return id;
        }


Yes, I understand that I cannot convert ProductDto from Product. How should I do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2021-03-16
@embiid

Use the mapper or manually create a new Product and assign field values ​​from ProductDto

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question