asp.net mvc 4 - AutoMapper not working **Probably failing for navigation properties** -


i have 2 classes:

class - country >> id, name, list

class - city >> id, name, countryid, country

i have countryviewmodel , cityviewmodel classes identical above classes.

i have written following in global.asax.cs:

automapper.mapper.createmap<country,countryviewmodel>(); automapper.mapper.createmap<city,cityviewmodel>(); 

after retrieving entities datbabse, firing following line map models view models.:

automapper.mapper.map(country, system.type.gettype("country"), system.type.gettype("countryviewmodel")); 

this giving "object reference not found" error on above line.

  1. make sure global.asax.cs includes call automapper.mapper.assertconfigurationisvalid() make sure mapped properly.

  2. i've never used non-generic syntax map before, generic version should work is:

    automapper.mapper.map<country, countryviewmodel>(country);


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -