I am learning about Unit of work, repository and service. Now I don't know how to update data in database
How to update the data based the id?
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using AutoMapper; using DataAccess; using DataAccess.UoW; using Model; namespace ClassLibrary1 { public class Service { private readonly Unit _uow; public Service() { _uow = new Unit(); } public IEnumerable<Mdl> GetAllLogins() { var logins = _uow.Register.GetAll().ToList(); if (logins.Any()) { var config = new MapperConfiguration(cfg => { cfg.CreateMap<Table_1, Mdl>(); }); IMapper mapper = config.CreateMapper(); var dest = mapper.Map<List<Table_1>, List<Mdl>>(logins); return dest; } return null; } public Mdl UpdateId(int Id) { var EmpId = _uow.Register.GetByID(Id); if(EmpId != null) { var config = new MapperConfiguration(cfg => { cfg.CreateMap<Mdl, Table_1>(); }); IMapper mapper = config.CreateMapper(); var dest = mapper.Map<Mdl, Table_1>(EmpId); //Issue Arises here return dest; } return null; } } } I get this error:
Cannot convert from DataAccess.Table1 to Model.Mdl
_uow.Register.GetByIDis returning? Is this returningTable_1type? Also you could put thevar config = new MapperConfiguration(cfg =>...inside the constructor. and theIMapper _mapper = config.CreateMapper();should beprivate readonly IMapper _mappercreate a instance of IMapper in the constructor you can use it in all methods of your class. Just some suggestions.