This project is read-only.

Basic Part Stub Breaks Blog When Added to Blog Post

Topics: Troubleshooting, Writing modules
Jun 22, 2012 at 8:06 PM
Edited Jun 22, 2012 at 8:11 PM

I have a part consisting of only the bare essentials needed to make it a part:

public class GoogleAnalyticsRecord : ContentPartRecord

public class GoogleAnalyticsPart : ContentPart<GoogleAnalyticsRecord>

public class Migrations : DataMigrationImpl
     public int Create()
cfg => cfg.Attachable()); return 1; } } public class GoogleAnalyticsDriver : ContentPartDriver<GoogleAnalyticsPart> { protected override DriverResult Display(GoogleAnalyticsPart part, string displayType, dynamic shapeHelper) { return ContentShape("Parts_GoogleAnalytics", () => shapeHelper.Parts_GoogleAnalytics()); } }

And of course the cshtml file, right now just a js alert that occurs only when in detail display type. Also, my removes it from summary display types.

When I add this part to a page or blog post, it behaves as expected. However, when I add it to the blog post content type I get nHybernate exceptions on the blog page (where the posts are listed).

The error:

2012-06-22 12:48:18,644 [37] NHibernate.AdoNet.AbstractBatcher - Could not execute query: SELECT top 10 this_.Id as Id649_10_, this_.Number as Number649_10_, this_.Published as Published649_10_, this_.Latest as Latest649_10_, this_.Data as Data649_10_, this_.ContentItemRecord_id as ContentI6_649_10_, bodypartre5_.Id as Id587_0_, bodypartre5_.Text as Text587_0_, bodypartre5_.Format as Format587_0_, bodypartre5_.ContentItemRecord_id as ContentI4_587_0_, autoroutep6_.Id as Id596_1_, autoroutep6_.UseCustomPattern as UseCusto2_596_1_, autoroutep6_.CustomPattern as CustomPa3_596_1_, autoroutep6_.DisplayAlias as DisplayA4_596_1_, autoroutep6_.ContentItemRecord_id as ContentI5_596_1_, titlepartr7_.Id as Id646_2_, titlepartr7_.Title as Title646_2_, titlepartr7_.ContentItemRecord_id as ContentI3_646_2_, contentite1_.Id as Id647_3_, contentite1_.Data as Data647_3_, contentite1_.ContentType_id as ContentT3_647_3_, commonpart3_.Id as Id585_4_, commonpart3_.OwnerId as OwnerId585_4_, commonpart3_.CreatedUtc as CreatedUtc585_4_, commonpart3_.PublishedUtc as Publishe4_585_4_, commonpart3_.ModifiedUtc as Modified5_585_4_, commonpart3_.Container_id as Container6_585_4_, googleanal10_.Id as Id591_5_, commentspa11_.Id as Id604_6_, commentspa11_.CommentsShown as Comments2_604_6_, commentspa11_.CommentsActive as Comments3_604_6_, fieldindex12_.Id as Id624_7_, tagspartre13_.Id as Id637_8_, contenttyp2_.Id as Id648_9_, contenttyp2_.Name as Name648_9_ FROM Orchard_Framework_ContentItemVersionRecord this_ left outer join Common_BodyPartRecord bodypartre5_ on this_.Id=bodypartre5_.Id left outer join Orchard_Autoroute_AutoroutePartRecord autoroutep6_ on this_.Id=autoroutep6_.Id left outer join Title_TitlePartRecord titlepartr7_ on this_.Id=titlepartr7_.Id inner join Orchard_Framework_ContentItemRecord contentite1_ on this_.ContentItemRecord_id=contentite1_.Id inner join Common_CommonPartRecord commonpart3_ on contentite1_.Id=commonpart3_.Id left outer join BankrateInsurance_GoogleAnalytics_GoogleAnalyticsRecord googleanal10_ on contentite1_.Id=googleanal10_.Id left outer join Orchard_Comments_CommentsPartRecord commentspa11_ on contentite1_.Id=commentspa11_.Id left outer join Orchard_Projections_FieldIndexPartRecord fieldindex12_ on contentite1_.Id=fieldindex12_.Id left outer join Orchard_Tags_TagsPartRecord tagspartre13_ on contentite1_.Id=tagspartre13_.Id inner join Orchard_Framework_ContentTypeRecord contenttyp2_ on contentite1_.ContentType_id=contenttyp2_.Id WHERE contenttyp2_.Name in (@p0) and commonpart3_.Container_id = @p1 and this_.Published = @p2 ORDER BY commonpart3_.CreatedUtc desc
System.Data.SqlClient.SqlException (0x80131904): Invalid object name 'BankrateInsurance_GoogleAnalytics_GoogleAnalyticsRecord'.

Any ideas? I can't think of a more stripped down part, what could possibly be causing this?

Jun 23, 2012 at 7:50 AM

Why do you even have a record there?

Jun 25, 2012 at 10:12 PM
Edited Jun 25, 2012 at 10:20 PM

@bertrandleroy - The short answer: I didn't know any better.

My reasoning was: since the driver is defined using a generic that takes a part, and a part is defined with a generic that takes a record, I needed to create a record for any part I wanted to build, even if I wasn't saving any data.

But I've now explored the code more, and have realized that there is a non-generic ContentPart. I'll use that for modules that don't need data persistence. All the examples I've seen start at the record level, and since it actually did work in most contexts, it didn't even occur to me to look for the non-generic ContentPart until now.

Jun 25, 2012 at 11:28 PM

Yes, a ContentPart optionally has some storage. You can even have several drivers for the same content part.