我正在尝试使用后台任务从Facebook Graph APi收集喜欢/评论,并使用它来驱动我们博客的趋势。
这里的trendingModels
已经被填充,并被用来填充TrendingParts.GraphId
和TrendingParts.TrendingValue
。
我没有得到任何异常,TrendingPart
上的属性指向TrendingPartRecord
中的字段。
但是数据库中没有任何东西存在,知道为什么吗?
_orchardsServices
是IOrchardServices
var articleParts = _orchardService.ContentManager.GetMany<TrendingPart>(
trendingModels.Select(r => r.OrchardId).ToList(),
VersionOptions.Published,
QueryHints.Empty);
// Cycle through the records and update them from the matching model
foreach (var articlePart in articleParts)
{
ArticleTrendingModel trendingModel = trendingModels.Where(r => r.OrchardId == articlePart.Id).FirstOrDefault();
if(trendingModel != null)
{
// Not persisting to the database, WHY?
// What's missing?
// If I'm understanding things properly nHibernate should push this to the db autoMagically.
articlePart.GraphId = trendingModel.GraphId;
articlePart.TrendingValue = trendingModel.TrendingValue;
}
}
编辑:可能值得注意的是,我可以在管理面板中更新和发布TrendingPart
上的字段,但保存的更改不会出现在MyModule_TrendingPartRecord
表中。
解决方案是使用ITransientDependency
将我的Service更改为瞬态依赖。
服务持有对PartRecords
数组的引用,因为它被视为Singleton,所以它从未被处理过,也从未向数据库推送过。