我正在使用Simple.Data检索数据,它将数据库表映射到一个动态对象。我想将动态对象映射到一个简单的类型。我试过这样做:
var dbObject = Database.Default.LocationStatus.FindByLocationStatusId(locationStatusId);
ILocationStatus domainObject = new LocationStatus();
domainObject.InjectFrom((object)dbObject);但是domainObject中没有设置任何属性。映射应该很简单,因为属性名称是相同的,ei: dbObject.Name和domainObject.Name。
我哪里出问题了?注:我实际上可以神奇地投(鸭子打字?)(LocationStatus)dbObject,但我想知道如何用ValueInjecter地图。谢谢。
发布于 2015-05-14 00:11:14
虽然听起来很奇怪,但几天前我遇到了同样的问题,解决办法很简单。
您也需要将您的动态输出转换为您想要映射的类型。
就我而言:
WeatherData myData = new WeatherData().InjectFrom((object)weatherData);如上述评论中所引用的帖子所示(我怀疑与原来的海报有相同的问题),但当使用.
WeatherData myData = new WeatherData().InjectFrom((object)weatherData) as WeatherData;一切都很好。
因此,即使使用较新的版本,几年后的3+仍然可能是一个问题,而转换输出类型是修复方法。
https://stackoverflow.com/questions/7766675
复制相似问题