c# - Mapping joined Domain Model to View Model using Automapper -


in business logic class joining 2 data models , returning controller ienumerable. need map these collection list using automapper .but not working expected.

logic class

 public ienumerable<object> getpurchaseorderdetailsbypersonid(long personid)     {         var purchaseorderdetails = pom in _unitofwork.dbset<purchaseordermain>()                                    join rep in _unitofwork.dbset<representativemaster>() on pom.repm_id equals rep.repm_id                                    pom.repm_id == personid                                    select new { pom.rm_id,pom.orderno,pom.orderamount,pom.orderdate ,rep.repname };          return purchaseorderdetails;     } 

controller

public actionresult index()     {         list<object> purchaseorder = _cls_purchaseorder_bll.getpurchaseorderdetailsbypersonid(personid).tolist();          return view(purchaseorder.toentity<omos.models.purchaseorderdetails>());     } 

toentity() in extension class

  public static list<tdestination> toentity<tdestination>(this list<object> objsource)     {         automapper.mapper.createmap<object, tdestination>();         list<tdestination> destination = new list<tdestination>();//handling null destination         foreach (object source in objsource)         {             destination.add(automapper.mapper.map<object, tdestination>(source));         }         return destination;     } 

but resulted mapping not expected.

change code this.

public static list<tdestination> toentity<tdestination>(this list<object> objsource)     {         list<tdestination> destination = new list<tdestination>();//handling null destination          foreach (object source in objsource)             destination.add(automapper.mapper.dynamicmap<tdestination>(source));          return destination;     } 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -