果园后台任务没有将PartRecords持久化到数据库中



我正在尝试使用后台任务从Facebook Graph APi收集喜欢/评论,并使用它来驱动我们博客的趋势。

这里的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表中。

解决方案是使用ITransientDependency将我的Service更改为瞬态依赖。

服务持有对PartRecords数组的引用,因为它被视为Singleton,所以它从未被处理过,也从未向数据库推送过。

最新更新