This project is read-only.

Tokens & Projections, SQL Transaction error

Topics: Writing modules
Feb 29, 2012 at 7:31 PM
Edited Feb 29, 2012 at 7:35 PM

I've created a Content Reference field that allows you to link content together through a field using a dropdown menu to select other content items. The list is populated by specifying a projection query to populate it with. Anyways, this part works fine.

In order to make better use of this I've tried to use Tokens to surface the currently viewed content item, so that you could for instance make a query that returns content that references the current item even if the projection was in a widget, without having to use the query string.

I've used this code in my token evaluation method:


if (area == "Contents" && !string.IsNullOrEmpty((string)routeData.Values["Id"])) {
    var item = _contentManager.Get(int.Parse((string)routeData.Values["Id"]));
    if (!context.Data.ContainsKey("Context")) {
        context.Data.Add("Context", item);
    context.For<IContent>("Context").Chain("This", "Content", content => item);


Now, to test this I went and created a projection on any set of content, say pages. I created a property based display with a rewrite token, such as

{Context.This.Id} : {Text}

And I receive this error: "The connection object can not be enlisted in transaction scope."

On the following SQL query: "While preparing SELECT this_.Id as Id65_2_, this_.Number as Number65_2_, this_.Published as Published65_2_, this_.Latest as Latest65_2_, this_.Data as Data65_2_, this_.ContentItemRecord_id as ContentI6_65_2_, contentite1_.Id as Id66_0_, contentite1_.Data as Data66_0_, contentite1_.ContentType_id as ContentT3_66_0_, contenttyp4_.Id as Id67_1_, contenttyp4_.Name as Name67_1_ FROM Orchard_Framework_ContentItemVersionRecord this_ inner join Orchard_Framework_ContentItemRecord contentite1_ on this_.ContentItemRecord_id=contentite1_.Id left outer join Orchard_Framework_ContentTypeRecord contenttyp4_ on contentite1_.ContentType_id=contenttyp4_.Id WHERE contentite1_.Id = @p0 and this_.Published = @p1 an error occurred"


Is this due to running my dev instance with SQL CE? Is there a workaround that will work for this situation or am I approaching this the wrong way?

Feb 29, 2012 at 10:17 PM

I got this to work by adding the item to the work context in an action filter and getting it from there in the token evaluation.