asp.net mvc - Mapp with automappaer -


i have model named word.

this word model

public class word : basefieldstables {     int id { get; set; }     string name { get; set; }     guid uniqid { get; set; }     datetime createddate { get; set; }     byte[] rowversion { set; get; }     public string text { get; set; }     public virtual category category { get; set; }     public int categoryid { get; set; }     public virtual language language { get; set; }     public int languageid { get; set; }      public virtual icollection<picture> pictures { get; set; }      [inverseproperty("mainword")]     public virtual icollection<relationshipbetweenwords> mainwords { get; set; }      [inverseproperty("relatedword")]     public virtual icollection<relationshipbetweenwords> relatedwords { get; set; } } 

word has category , language and...

for example language model

    public class language : basefieldstables     {        int id { get; set; }         string name { get; set; }         guid uniqid { get; set; }         datetime createddate { get; set; }         byte[] rowversion { set; get; }         public virtual icollection<word> words { get; set; }     } 

i have word word viewmodel this

public class wordviewmodel      public string name { get; set; }       public ilist<selectlistitem> categories { set; get; }       [hiddeninput(displayvalue = false)]     public int selectedcategoryid { set; get; }       public ilist<selectlistitem> languages { set; get; }        [hiddeninput(displayvalue = false)]     public int selectedlanguageid { set; get; } } 

and controller

public actionresult index(     {         ilist<word> list = _wordservice.getall();      } 

i want word , map(auotomapper) wordviewmodel languagename , category name , return in view please me if have change wordviewmodel or... , how map.tnx

oh found it

public actionresult index()         {             var orders = _respository.getall();              automapper.mapper.createmap<order, orderdto>()                 .formember(dest => dest.ordernumber, opt => opt.mapfrom(src => src.orderno))                 .formember(dest => dest.orderitemsdto, opt => opt.ignore());              var model = automapper.mapper.map<ienumerable<order>, ienumerable<orderdto>>(orders);              return view(model);         } //razor view code <h2>orders</h2> <table>     <tr>         <th>order number</th>         <th>name</th>         <th>total</th>     </tr> @foreach (var item in model) {     <tr>         <td>@item.ordernumber</td>         <td>@item.customername</td>         <td>$@item.total</td>     </tr> } </table> 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -