c# - EF - Error in converting type Dataaccess.Employees to ViewModels.Employee -


i have view model class called employee , ef entity called employees. if write below query error stating "cannot convert types, explicit conversion exists) know how solve using select new viewmodel.employee clause, wondering there concise way resolve ? appreciated -thanks

var selectedemployee = (from q in emsctx.employees                                                 q.id == employee.id                                                 select q).tolist().firstordefault();                        employeedata.employees = selectedemployee;      

if have 2 different types, if have same properties, need mapping between them. can in many different ways, tool automapper can help. automapper if have types largely (or completely) similar in public properties have.

automapper allow make mapping configuration between 2 types , map them.

for example, this:

mapper.createmap<dataaccess.employee, viewmodels.employee>();  var dataemployee = // data access  var viewmodelemployee = mapper.map(dataemployee); 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -