Map collection of objects

后端 未结 2 1594
再見小時候
再見小時候 2020-12-16 09:37

I am trying to introduce Automapper into an application for the first time, but I keep getting an error saying I have some invalid arguments.

My model:



        
相关标签:
2条回答
  • 2020-12-16 09:53

    You are mapping collections, not single entities (IEnumerable<Store> to IEnumerable<StoreVM>), so use this mapping

    var VMstores = Mapper.Map<IEnumerable<Store>, IEnumerable<StoreVM>>(stores);
    
    0 讨论(0)
  • 2020-12-16 10:09

    Update! Now you can do this:

    var VMstores = stores.Project().To<StoreVM>();
    
    0 讨论(0)
提交回复
热议问题