November Happy Hour will be moved to Thursday December 5th.

Anders Hattestad
May 16, 2011
  3164
(0 votes)

Quick tip with DDS and Linq

I have had trouble with a simple Linq statement.

Code Snippet
  1. public static T GetMyRow(PageReference pageRef)
  2. {
  3.     var query = from item in Items where
  4.     item.PageReferenceString == pageRef.CreateReferenceToPublishedPage().ToString()
  5.     select item;

 

It kept throwing errors like

Methods not supported for type System.Object

Even when I rewrote it to

Code Snippet
  1. public static T GetMyRow(PageReference pageRef)
  2. {
  3.     var query = from item in Items where
  4.     item.PageReferenceString == (pageRef.CreateReferenceToPublishedPage().ToString())
  5.     select item;

I got the same error,

But if I make a function that returned a string like this:

Code Snippet
  1. public static string PageRefAsString(PageReference pageRef)
  2. {
  3.     return pageRef.CreateReferenceToPublishedPage().ToString();
  4. }
  5. public static T GetMyRow(PageReference pageRef)
  6. {
  7.     var query = from item in Items
  8.     where item.PageReferenceString == PageRefAsString(pageRef)
  9.     select item;

I didn’t get the error. I guess there are something with what get executed or evaluated first, or something. But if you get this error message: Methods not supported for type System.Object. Maybe this is your problem, and you can save your self some time debugging it Smile. Cause I used some time before I finally got it to work.

May 16, 2011

Comments

smithsson68@gmail.com
smithsson68@gmail.com May 16, 2011 02:32 PM

Hi,

I'll report this as a bug.

Thanks for sharing.

/Paul.

May 27, 2011 01:11 PM

Currently we're not supporting .ToString() in a LINQ query. It doesn't matter if it's a method or a property. I hope we will support this soon.

/ Jonas

Please login to comment.
Latest blogs
Optimizely SaaS CMS + Coveo Search Page

Short on time but need a listing feature with filters, pagination, and sorting? Create a fully functional Coveo-powered search page driven by data...

Damian Smutek | Nov 21, 2024 | Syndicated blog

Optimizely SaaS CMS DAM Picker (Interim)

Simplify your Optimizely SaaS CMS workflow with the Interim DAM Picker Chrome extension. Seamlessly integrate your DAM system, streamlining asset...

Andy Blyth | Nov 21, 2024 | Syndicated blog

Optimizely CMS Roadmap

Explore Optimizely CMS's latest roadmap, packed with developer-focused updates. From SaaS speed to Visual Builder enhancements, developer tooling...

Andy Blyth | Nov 21, 2024 | Syndicated blog

Set Default Culture in Optimizely CMS 12

Take control over culture-specific operations like date and time formatting.

Tomas Hensrud Gulla | Nov 15, 2024 | Syndicated blog