Orchard 后台任务不会将 PartRecords 保存到数据库

Orchard background task not persisting PartRecords to the database

我正在尝试使用后台任务从 Facebook Graph APi 收集 Likes/Comments 并使用它来推动我们博客的趋势。

此处 trendingModels 已经填充并用于填充 TrendingParts.GraphIdTrendingParts.TrendingValue

我没有收到任何异常,TrendingPart 上的属性指向 TrendingPartRecord 中的字段。

然而没有任何东西保存到数据库中,知道为什么吗?

_orchardsServicesIOrchardServices

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 table 中。

解决方案是使用 ITransientDependency.

将我的服务更改为临时依赖项

该服务持有对 PartRecords 数组的引用,因为它被视为一个单例,所以它从未被释放,也从未被推送到数据库。