我正在运行Orchard CMS 1.7.2。我创建了一个名为BYUtv.Shapes
的自定义模块作为存储可重用形状方法的位置。我在这个模块中有一个名为RelatedToShow : IDependency
的类。此类中感兴趣的方法称为RelatedEpisodes
。此形状方法的目的是通过在admin ui中创建的查询,检索与特定Show相关的剧集的剧集数据。在管理器中,剧集内容类型定义具有内容选择器字段,其允许内容管理者选择剧集是剧集的一部分或与之相关的节目。我创建的查询正常工作并返回正确的数据。有了这个解释,这是我的形状方法。
[Shape]
public IHtmlString RelatedEpisodes(dynamic Shape, dynamic Display, int? PageSize, string PagerSuffix = "")
{
// Retrieves the QueryPart by name for the query called Related Episodes Year.
// Related Episodes Year retrieves Episodes that are related to a specific show with an optional year filter.
QueryPart episodesQuery = GetQueryPartByName("Related Episodes Year");
dynamic pager = CreatePager(Shape, _projectionManager.GetCount(episodesQuery.Id), PageSize, PagerSuffix);
int startIndex = pager.Pager.GetStartIndex();
int pageSize = pager.Pager.PageSize;
IEnumerable<ContentItem> contentItems = new List<ContentItem>();
if(episodesQuery != null)
{
contentItems = _projectionManager.GetContentItems(episodesQuery.Id, startIndex, pageSize);
}
// Retrieves the QueryPart by name for the query called Related Episodes.
// Related Episodes retrieves Episodes that are related to a specific show.
QueryPart newestEpisodeQuery = GetQueryPartByName("Related Episodes");
ContentItem newestEpisode = null;
if (newestEpisodeQuery != null)
{
newestEpisode = _projectionManager.GetContentItems(newestEpisodeQuery.Id, 0, 1).FirstOrDefault();
}
// Retrieves a list of distinct years that the episodes premiered in.
List<string> years = _projectionManager.GetContentItems(newestEpisodeQuery.Id).Select(y => (string)((dynamic)y).TimeSpanPart.StartDateTime.Year.ToString()).Distinct().ToList();
return Display.RelatedEpisodesView(ContentItems: contentItems, Pager: pager, NewestEpisode: newestEpisode, YearFilter: GetYearFilter(), Years: years);
}
在我的所有测试中,这总是在本地工作。它也适用于生产,但似乎随机地崩溃了它在生产中使用的页面。如果我评论在生产中运行此shape方法的代码,则根据需要运行页面的其余部分。我在生产和本地之间了解的唯一区别可能是HostCompontents.config文件和流量。在制作中我关闭了几个属性,因为我知道它会有助于提高性能。
以下是来自生产服务器的日志。
Exception information:
Exception type: AssertionFailure
Exception message: collection was processed twice by flush()
at NHibernate.Engine.Collections.PrepareCollectionForUpdate(IPersistentCollection collection, CollectionEntry entry, EntityMode entityMode, ISessionFactoryImplementor factory) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Engine\Collections.cs:line 164
at NHibernate.Event.Default.AbstractFlushingEventListener.FlushCollections(IEventSource session) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\AbstractFlushingEventListener.cs:line 92
at NHibernate.Event.Default.AbstractFlushingEventListener.FlushEverythingToExecutions(FlushEvent event) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\AbstractFlushingEventListener.cs:line 61
at NHibernate.Event.Default.DefaultAutoFlushEventListener.OnAutoFlush(AutoFlushEvent event) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\DefaultAutoFlushEventListener.cs:line 32
at NHibernate.Impl.SessionImpl.AutoFlushIfRequired(ISet`1 querySpaces) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\SessionImpl.cs:line 1180
at NHibernate.Impl.SessionImpl.List(String query, QueryParameters queryParameters, IList results) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\SessionImpl.cs:line 616
at NHibernate.Impl.SessionImpl.List(String query, QueryParameters parameters) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\SessionImpl.cs:line 593
at NHibernate.Impl.QueryImpl.List() in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\QueryImpl.cs:line 64
at NHibernate.Impl.AbstractQueryImpl.UniqueResult() in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\AbstractQueryImpl.cs:line 960
at Orchard.ContentManagement.DefaultHqlQuery.Count() in c:\Source\BYUB\byuradio2\orchard\src\Orchard\ContentManagement\DefaultHqlQuery.cs:line 212
at Orchard.Projections.Services.ProjectionManager.<GetCount>b__14(IHqlQuery contentQuery)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.Sum(IEnumerable`1 source)
at Orchard.Projections.Services.ProjectionManager.GetCount(Int32 queryId)
at BYUtv.Shapes.Drivers.RelatedToShow.RelatedEpisodes(Object Shape, Object Display, Nullable`1 PageSize, String PagerSuffix)
和
Stack trace: at NHibernate.Engine.Collections.PrepareCollectionForUpdate(IPersistentCollection collection, CollectionEntry entry, EntityMode entityMode, ISessionFactoryImplementor factory) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Engine\Collections.cs:line 164
at NHibernate.Event.Default.AbstractFlushingEventListener.FlushCollections(IEventSource session) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\AbstractFlushingEventListener.cs:line 92
at NHibernate.Event.Default.AbstractFlushingEventListener.FlushEverythingToExecutions(FlushEvent event) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\AbstractFlushingEventListener.cs:line 61
at NHibernate.Event.Default.DefaultAutoFlushEventListener.OnAutoFlush(AutoFlushEvent event) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\DefaultAutoFlushEventListener.cs:line 32
at NHibernate.Impl.SessionImpl.AutoFlushIfRequired(ISet`1 querySpaces) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\SessionImpl.cs:line 1180
at NHibernate.Impl.SessionImpl.List(String query, QueryParameters queryParameters, IList results) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\SessionImpl.cs:line 616
at NHibernate.Impl.SessionImpl.List(String query, QueryParameters parameters) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\SessionImpl.cs:line 593
at NHibernate.Impl.QueryImpl.List() in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\QueryImpl.cs:line 64
at NHibernate.Impl.AbstractQueryImpl.UniqueResult() in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\AbstractQueryImpl.cs:line 960
at Orchard.ContentManagement.DefaultHqlQuery.Count() in c:\Source\BYUB\byuradio2\orchard\src\Orchard\ContentManagement\DefaultHqlQuery.cs:line 212
at Orchard.Projections.Services.ProjectionManager.<GetCount>b__14(IHqlQuery contentQuery)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.Sum(IEnumerable`1 source)
at Orchard.Projections.Services.ProjectionManager.GetCount(Int32 queryId)
at BYUtv.Shapes.Drivers.RelatedToShow.RelatedEpisodes(Object Shape, Object Display, Nullable`1 PageSize, String PagerSuffix)
错误似乎总是与collection was processed twice by flush()
有关。我甚至尝试在代码中直接创建查询,结果类似。
发布的另一个问题是Orchard cms 1.7.2 GenericADOException。那里表达的一些副作用与我所拥有的类似。
您是否可以在此代码中看到导致这些错误的明显问题? 你遇到过这个或类似的问题吗? 有关如何解决这个问题的任何想法?