2

I'm retrieving data with Simple.Data - which maps the database table to a dynamic object. I want to map the dynamic object to a simple type. I have tried this:

var dbObject = Database.Default.LocationStatus.FindByLocationStatusId(locationStatusId);
ILocationStatus domainObject = new LocationStatus();
domainObject.InjectFrom((object)dbObject);

But no properties in the domainObject are set. The mapping should be simple as the property names are the same, ei: dbObject.Name and domainObject.Name

Where am I going wrong? Note: I can in fact magically cast (duck typing?) (LocationStatus)dbObject but I'd like to know how to map with ValueInjecter. Thanks.

Neil Thompson
  • 6,356
  • 2
  • 30
  • 53
  • 1
    it should work if the properties have the same name and type, look here: http://valueinjecter.codeplex.com/discussions/240346 – Omu Oct 15 '11 at 09:21
  • 1
    Ye, that's where I got the original code. I must be missing something. Thanks for your help chuck. – Neil Thompson Nov 17 '11 at 20:41

1 Answers1

0

Strange as it may sound, I ran into this same problem a few days ago, and the solutions was simple.

You need to cast the output of your dynamic to the type your trying to map too.

In my case:

WeatherData myData = new WeatherData().InjectFrom((object)weatherData);

as shown in the post referenced in the comments above didn't work (I suspect with the same problem as the original poster), but when cast using as ...

WeatherData myData = new WeatherData().InjectFrom((object)weatherData) as WeatherData;

Everything works fine.

So it seems even with the newer versions, 3+ years later this can still be an issue, and casting the output type is the fix.

shawty
  • 5,729
  • 2
  • 37
  • 71