0

I have the standard repository pattern with a service layer and I need to map a POCO object called Game:

public class Game
{    
    public int Id { get; set; }
    public int GameTypeId { get; set; }
    public int GameStateId { get; set; }
    public int? PreviousGameId { get; set; }
    public DateTime EndOn { get; set; }
    public DateTime StartOn { get; set; }
}

to map it to a view model that has a member called GameId. So Id > GameId.

However when I create my mapping convention the object is coming in with what looks like a GUID attached to the end of it.

How can I get value injector to map these POCO objects properly without mapping from the dynamic proxy to a POCO.. or is that not possible?

Ryan
  • 4,354
  • 2
  • 42
  • 78
  • you should show the full code for your model and viewmodel, and show the source Property in M and target property in VM – Omu Apr 06 '12 at 09:39

3 Answers3

0

I ended up turning off proxy generation and lazy loading and now I just eagar load everything

Ryan
  • 4,354
  • 2
  • 42
  • 78
0

Saw the same problem today with Entity Framework Dynamic Proxies. Here's how to make ValueInjecter work without disabling proxies.

I had used Mapper.AddMap to create a custom map, based on the non-proxy class. At run-time my call to Mapper.Map did not get matched to my map because it received the proxy class.

var customerInput = Mapper.Map<CustomerInput>(customer); //runs default map

When I called Mapper.Map with both input and output types it worked!

var customerInput = Mapper.Map<Customer, CustomerInput>(customer); //runs custom map
BillVo
  • 565
  • 1
  • 5
  • 20
-1

Try doing an explicit cast of the proxy to the underlying POCO'S type before mapping it.

D-Man
  • 62
  • 4
  • Casting the input object for the Mapper.Map does not cause a custom map to be selected. Map still sees the prior type. – BillVo Nov 13 '18 at 19:56